diff --git a/otoroshi/app/env/Env.scala b/otoroshi/app/env/Env.scala index b9caf5a81..aab468ded 100644 --- a/otoroshi/app/env/Env.scala +++ b/otoroshi/app/env/Env.scala @@ -193,6 +193,9 @@ class Env( private lazy val halloweenStop = DateTime.now().withMonthOfYear(10).withDayOfMonth(31).plusDays(1).withMillisOfDay(1) + lazy val jsonPathNullReadIsJsNull = + configuration.getOptionalWithFileSupport[Boolean]("otoroshi.options.jsonPathNullReadIsJsNull").getOrElse(false) + lazy val dynamicBodySizeCompute = configuration.getOptionalWithFileSupport[Boolean]("otoroshi.options.dynamicBodySizeCompute").getOrElse(true) diff --git a/otoroshi/app/utils/jsonpath.scala b/otoroshi/app/utils/jsonpath.scala index 9603ccde8..74cef0581 100644 --- a/otoroshi/app/utils/jsonpath.scala +++ b/otoroshi/app/utils/jsonpath.scala @@ -86,6 +86,8 @@ object JsonPathUtils { // } } + private lazy val jsonPathNullReadIsJsNull = OtoroshiEnvHolder.get().jsonPathNullReadIsJsNull + def getAtPolyF(payload: String, path: String): Either[JsonPathReadError, JsValue] = { //val env = OtoroshiEnvHolder.get() //env.metrics.withTimer("JsonPathUtils.getAtPolyF") { @@ -95,7 +97,11 @@ object JsonPathUtils { if (read != null) { Right(Writes.jsonNodeWrites.writes(read)) } else { - Left(JsonPathReadError("null read", path, payload, None)) + if (jsonPathNullReadIsJsNull) { + Right(JsNull) + } else { + Left(JsonPathReadError("null read", path, payload, None)) + } } } match { case Failure(e) => Left(JsonPathReadError("error while trying to read", path, payload, e.some)) diff --git a/otoroshi/conf/application.conf b/otoroshi/conf/application.conf index 9cef2ae64..90cabf54a 100644 --- a/otoroshi/conf/application.conf +++ b/otoroshi/conf/application.conf @@ -1033,6 +1033,8 @@ otoroshi { } } options { + jsonPathNullReadIsJsNull = false + jsonPathNullReadIsJsNull = ${?OTOROSHI_OPTIONS_JSONPATHNULLREADISJSNULL} bypassUserRightsCheck = false bypassUserRightsCheck = ${?OTOROSHI_OPTIONS_BYPASSUSERRIGHTSCHECK} emptyContentLengthIsChunked = true