Comments (4)
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.
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.
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.
Hey @celadari,
Any update on this enhancement ?
from json-logic-scala.
Related Issues (1)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json-logic-scala.