GithubHelp home page GithubHelp logo

Comments (4)

grzegorz-taramina avatar grzegorz-taramina commented on May 26, 2024 1

Hey @celadari,
Thanks for the reply.
I've managed to solve this issue overriding deserializeValueLogic function (Deserializer) like that:

`override protected[this] def deserializeValueLogic(jsonLogic: JsObject, jsonLogicData: JsObject): ValueLogic[_] = {
val isTypeDefined = (jsonLogic \ "type").isDefined
val typeValueOpt = Deserializer.unmarshType(jsonLogic \ "type")
val pathData = (jsonLogic \ "var").as[String]
val split = pathData.split("\.")

val lookUpPathData = if (split.isEmpty) {
  jsonLogicData \ pathData
} else {
  split.tail.foldLeft(jsonLogicData \ split.head)((b, a) => {
    b \ a
  })
}
val jsValue = lookUpPathData.getOrElse(JsNull)

if (isTypeDefined && lookUpPathData.isEmpty) {
  throw new InvalidJsonParsingException(s"""Error while parsing ValueLogic of type value: "var" $pathData is undefined""")
}
if (!isTypeDefined && lookUpPathData.isDefined) {
  throw new InvalidJsonParsingException(
    """Error while parsing ValueLogic of type variable: "var" must not be a key on data dictionary.""" +
      s"""\nActual: "$pathData"""")
}

val valueOpt = typeValueOpt.flatMap(typeValue => Option(getUnmarshaller(typeValue).unmarshal(jsValue)))
val variableNameOpt = if (lookUpPathData.isDefined) None else Some(pathData)
val pathDataOpt = if (lookUpPathData.isDefined) Some(pathData) else None

ValueLogic(valueOpt, typeValueOpt, variableNameOpt, pathDataOpt)

}`

Maybe it's worth adding that to the library as usual scenario for using jsonlogic is passing complex objects to jsonlogic engine.

Cheers

from json-logic-scala.

celadari avatar celadari commented on May 26, 2024 1

Clever move, I will check if adding this line doesn't break unit and functional tests.

I'll let you know :)

from json-logic-scala.

celadari avatar celadari commented on May 26, 2024

Hello @grzegorz-taramina ,

Sorry for the late reply (I was afk for the last two weeks).

Current version do not accept accessing in nested data object. This can be added.

Is one of these alternatives what you're looking for:

  • put every field at root level (I think this is not what you're looking for)
  • define a type Booking (`case class Booking(ref){def } {def $less(num: java.lang.Integer): java.lang.Boolean = ref < num}' )

If not what you're looking for, we can see how to add the nested data structure field accessing

from json-logic-scala.

grzegorz-taramina avatar grzegorz-taramina commented on May 26, 2024

Hey @celadari,
Any update on this enhancement ?

from json-logic-scala.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.