I'm able to successfully generate JSON file from Maximo however I would like to modify the JSON before it gets generated. Like below is the sample JSON that gets generated in Maximo,
{"lastreadingdate":"2020-01-30T16:48:33+01:00",
"linearassetmeterid":0,
"sinceinstall":0.0,
"lastreading":"1,150",
"plustinitrdng":0.0,
"sincelastinspect":0.0,
"_rowstamp":"568349195",
"assetnum":"RS100003",
"active":true,
"assetmeterid":85,
"lifetodate":0.0,
"measureunitid":"KWH",
"metername":"1010",
"remarks":"TESTING JSON"}
I need the JSON to be generated as below ,
{"spi:action": "OSLC draft",
"spi:tri1readingdate":"2020-01-30T16:48:33+01:00",
"spi:tryassetmeterid":0,
"spi:install":0.0,
"spi:lastreadingTx":"1,150",
"spi:intrdngtrX":0.0,
and so on...}
Basically I need to change the target attribute names and prefix "spi" Below is the error occuring in JSON Mapping .
You're not specifying how you generate the JSON file but I'll quickly explain how you can achieve this:
As Dex pointed out, there is a JSON Mapping app in the integration module that you can use to map your outbound object structure's fields to your target structure naming.
You define your JSON structure on the JSON Mapping tab by providing a JSON sample.
You then define your mapping with Maximo on the Properties tab, like this:
Reading this IBM doc before jumping right into it should help you a lot:
https://www.ibm.com/developerworks/community/wikis/form/anonymous/api/wiki/02db2a84-fc66-4667-b760-54e495526ec1/page/e10f6e96-435d-433c-8259-5690eb756779/attachment/169224c7-10a5-4cee-af72-697a476f8b2e/media/JSON
Is this possible to have a node property as json raw string and to filter on it with cypher ?
I have a node with some defined properties and metadata (json raw string).
I would like to select or filter on those metadata property.
This is something like this :
START movie=node:TYPE_INDEX(Type = 'MOVIE') // Start with the reference
MATCH movie-[t:TAG]->tag
WHERE collect(movie.Metadata).RatingPress > 3
RETURN distinct movie.Label
And metadata are something like this :
{"RatingPress" : "0","RatingSpectator" : 3"}
I have expected to use collect function in order to call the property like this :
collect(movie.Metadata).RatingPress
But, of course it fails...
Is this a way to bind some json string from a node property with cypher ?
Thanks for your help
That's going against the principles of properties. Why not set the properties in the JSON metadata directly on the node?
But to answer your question:
No, cypher has no knowledge about JSON.
We treat the entire Node as a JSON blob. Since Neo4j doesn't support hierarchical properties, we flatten out the JSON into delimited property names on save and unflatten them on read. You can then form Cypher queries on (for example) property name "foo.bar.baz". The queries tend to look a bit funky because you'll need to quote them using single back quotes, but it works.
I'm trying to parse a grails parameter map to a Json String, and then back to a parameter map. (For saving html form entries with constraint-violations)
Everything is fine as long as there is no hasMany relationship in the parameter-map.
I'm using
fc.parameter = params as JSON
to save the params as JSON String.
Later I'm trying to rebuild the parameter map and create a new Domain-Object with it:
new Foo(JSON.parse(fc.parameter))
Everything is fine using only 1:1 relationships (states).
[states:2, listSize:50, name:TestFilter]
But when I try to rebuild a params-map with multi-select values (states)
[states:[1,2], listSize:50, name:TestFilter]
I'm getting this IllegalStateException:
Failed to convert property value of type org.codehaus.groovy.grails.web.json.JSONArray to required type java.util.Set for property states; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [de.gotosec.approve.State] for property states[0]: no matching editors or conversion strategy found
I tried to use this, but without success:
JSON.use("deep") {
new Foo(JSON.parse(fc.parameter))
}
You can use JsonSlurper instead of the converters.JSON of grails, it maps JSON objects to Groovy Maps. I think this link also might help you.
Edit: Now, if the problem is binding the params map to your domain, you should try using bindData() method, like:
bindData(foo, params)
Note that this straightforward use is only if you're calling bindData inside a controller.
What seems to be happening in your case is that Grails is trying to bind a concrete type of List (ArrayList in the case of JsonSlurper and JSONArray in the case of converters.JSON) into a Set of properties (which is the default data structure for one-to-many associations). I would have to take a look at your code to confirm that. But, as you did substitute states: [1,2] for a method of your app, try another test to confirm this hypothesis. Change:
states:[1,2]
for
states:[1,2] as Set
If this is really the problem and not even bindData() works, take a look at this for a harder way to make it work using object marshalling and converters.JSON. I don't know if it's practical for you to use it in your project, but it sure works nicely ;)
I get json data from Struts Action, like below:
I want to precoss this data in JSP page, but I tried to use .$each or attr, all does not woek, I use Json2.js JSON.stringfy() get these data, so how I can fet each key and value in it?
[{"agreementNumber":"161446628","employeeIndicator":"N","enrollmentSrc":"363","fepIndicator":"N","groupCancelDate":null,"groupCancelDateTime":0,"groupCnlDate":"","groupEffDate":"20070701","groupEffectiveDate":{"date":1,"day":0,"hours":0,"minutes":0,"month":6,"seconds":0,"time":1183262400000,"timezoneOffset":240,"year":107},"groupEffectiveDateTime":1183262400000,"groupName":"Westminster College","groupNumber":"01501701 ","index":"1","memberList":{"enrollmetSrc":"363","groupNumber":"01501701 ","memberList":[{"agreementNumber":"161446628","birthDate":{"date":10,"day":0,"hours":0,"minutes":0,"month":1,"seconds":0,"time":-217450800000,"timezoneOffset":300,"year":63},"birthDateTime":-217450800000,"cancelDate":null,"cancelDateTime":0,"classCode":" I3","effectiveDate":{"date":1,"day":0,"hours":0,"minutes":0,"month":6,"seconds":0,"time":1183262400000,"timezoneOffset":240,"year":107},"effectiveDateTime":1183262400000,"firstName":"KENNETH ","gender":"M","groupName":"","groupNumber":"01501701 ","lastName":"ROMIG ","medicareAdvantage":"","memberId":375315,"middleName":"J ","pin":"1","preTtlName":" ","relation":"Self","relationCode":"1","sucTtlName":" "},{"agreementNumber":"161446628","birthDate":{"date":23,"day":5,"hours":0,"minutes":0,"month":7,"seconds":0,"time":-200692800000,"timezoneOffset":240,"year":63},"birthDateTime":-200692800000,"cancelDate":null,"cancelDateTime":0,"classCode":" I3","effectiveDate":{"date":1,"day":0,"hours":0,"minutes":0,"month":6,"seconds":0,"time":1183262400000,"timezoneOffset":240,"year":107},"effectiveDateTime":1183262400000,"firstName":"KIMBERLY ","gender":"F","groupName":"","groupNumber":"01501701 ","lastName":"ROMIG ","medicareAdvantage":"","memberId":1424959,"middleName":"G ","pin":"3","preTtlName":" ","relation":"Spouse","relationCode":"2","sucTtlName":" "},{"agreementNumber":"161446628","birthDate":{"date":8,"day":1,"hours":0,"minutes":0,"month":0,"seconds":0,"time":631774800000,"timezoneOffset":300,"year":90},"birthDateTime":631774800000,"cancelDate":null,"cancelDateTime":0,"classCode":" I3","effectiveDate":{"date":1,"day":0,"hours":0,"minutes":0,"month":6,"seconds":0,"time":1183262400000,"timezoneOffset":240,"year":107},"effectiveDateTime":1183262400000,"firstName":"NICOLE ","gender":"F","groupName":"","groupNumber":"01501701 ","lastName":"CRUMBACHER ","medicareAdvantage":"","memberId":375314,"middleName":"A ","pin":"4","preTtlName":" ","relation":"Child","relationCode":"3","sucTtlName":" "},{"agreementNumber":"161446628","birthDate":{"date":7,"day":6,"hours":0,"minutes":0,"month":6,"seconds":0,"time":994478400000,"timezoneOffset":240,"year":101},"birthDateTime":994478400000,"cancelDate":null,"cancelDateTime":0,"classCode":" I3","effectiveDate":{"date":1,"day":0,"hours":0,"minutes":0,"month":6,"seconds":0,"time":1183262400000,"timezoneOffset":240,"year":107},"effectiveDateTime":1183262400000,"firstName":"NATHAN ","gender":"M","groupName":"","groupNumber":"01501701 ","lastName":"ROMIG ","medicareAdvantage":"","memberId":1424960,"middleName":"J ","pin":"6","preTtlName":" ","relation":"Child","relationCode":"3","sucTtlName":" "}]},"ownerCode":"HM"}]
Your json object has a complex structure so I am not going to write the function how to map it properly but I am going to give you some tools how to understand it better and work with it.
To see your json object more clearly use a an online json pareser http://json.parser.online.fr/ just paste your json object there and in the right you will see the tree like structure.
Here you can see examples how to access you json object properties jsfidle
I know that this is not what you want exactly but will help you build it.
I'm trying to replace a custom JSON (de)serialization in a groovy/grails project with Jackson.
I'm having trouble getting Jackson to output a pretty-printed JSON with keys sorted in a simple 'natural' alphabetic order.
I've tried this (and many variations):
mymap = [ ... ] // Some groovy map
def mapper = new ObjectMapper()
mapper.configure(SerializationConfig.Feature.SORT_PROPERTIES_ALPHABETICALLY, true)
def jsonstring = mapper.defaultPrettyPrintingWriter().writeValueAsString(mymap)
But Jackson stubbornly generates a JSON where the keys seem to be in a random order.
I've tried changing the type of 'mymap' with a TreeMap, and in that case all keys are properly sorted as expected.
I'm wondering if there is a way to get the keys sorted without changing 'mymap' above to a TreeMap (and recursively all of its map values...).
SORT_PROPERTIES_ALPHABETICALLY seems to be intended to do precisely that, but it's not doing it for some reason.
Would you know why that is? Anything I'm doing wrong above?
I've tried with Jackson 1.8.3, 1.8.8 and 1.9.5, same result (random keys).
As stated by #tim_yates, this doesn't work for map keys.
You could use
mapper.configure(SerializationConfig.Feature.ORDER_MAP_ENTRIES_BY_KEYS, true)
With newer version ( >= 2.6.1) the API changed to:
mapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);
The documentation for SORT_PROPERTIES_ALPHABETICALLY explicitly says:
Feature that defines default property serialization order used for POJO fields (note: does not apply to Map serialization!)
So I guess you will need to change your input Map (as you say)
As pointed out, this feature just works for POJOs. However, I think there is a feature request to do the same for Maps, at Jackson Jira; and if not, this sounds like a good addition.
But in the meantime I would second #tim_yates suggestion to use intermediate TreeMap for sorting, serializing that: ordering that Map has will be used as is, so this should work.