How to parse JSON-LD data in java and turn it into a java object - json-ld

I don't know what kind of format is inside the JSON-LD, but it needs to be converted into a well-defined object.
My question is I don't know what kind of JSON-LD data is uploaded by the client and I don't know if it is possible to convert such data into some object with a well-defined format.
Do you have a solution yet?

If you don't know the structure of the object beforehand, you will probably have to use some generic structure to hold the data in Java. If you use a library like jsonld-java, it will do exactly that. You will work with Maps and Lists and it should be able to accommodate basically any JSON-LD data.
If you did know the target structure (for example, if it were one of several types for which you have a Java class), you could use a library like JB4JSON-LD to load it into an object of that class.
Disclaimer: I am the author of the JB4JSON-LD library.

Related

Is it better to use Row or GenericRowData with DataStream API?

I Am working with flink 1.15.2, should i use Row or GenericRowData that inherit RowData for my own data type?, i mostly use streaming api.
Thanks.
Sig.
In general the DataStream API is very flexible when it comes to record types. POJO types might be the most convenient ones. Basically any Java class can be used but you need to check which TypeInformation is extracted via reflection. Sometimes it is necessary to manually overwrite it.
For Row you will always have to provide the types manually as reflection cannot do much based on class signatures.
GenericRowData should be avoided, it is rather an internal class with many caveats (strings must be StringData and array handling is not straightforward). Also GenericRowData becomes BinaryRowData after deserialization. TLDR This type is meant for the SQL engine.
The docs are actually helpful here, I was confused too.
The section at the top titled "All Known Implementing Classes" lists all the implementations. RowData and GenericRowData are described as internal data structures. If you can use a POJO, then great. But if you need something that implements RowData, take a look at BinaryRowData, BoxedWrapperRowData, ColumnarRowData, NestedRowData, or any of the implementations there that aren't listed as internal.
I'm personally using NestedRowData to map a DataStream[Row] into a DataStream[RowData] and I'm not at all sure that's a good idea :) Especially since I can't seem to add a string attribute

UTFDataFormatException - encoded string too long

In my mobile app I have an object implementing PropertyBusinessObject which contains numerous other objects also implementing this interface. This object structure is populated by JSON data I am getting back from my server. When I try to write this object to Storage with writeObject() I get the above error. The stacktrace shows it originating in the com.codename1.io.Util.writeObject() method where it is writing UTF-8 (limited to 64k). The developer guide does not reference any potential issues with Storage and recommends it over FileSystemStorage. My question is, is there a workaround/update for this? Would I have to revert to writing out the object structure to the filesystem? Thanks.
If you have a ridiculously long string e.g. to represent the contents of the file I would suggest rethinking that. Strings are inefficient in Codename One since we need to copy their representation into the iOS native layer. Also writing them to UTF is very wasteful if what you need is a binary representation. I suggest using a byte array.
Serializing to storage is a simple approach. It works great for small objects. If you have larger objects you might want to store them individually. You can also serialize to/from JSON so your storage data is readable.

Is there an intermediate representation in PlantUML that can be used for further processing?

I'd like to use the PlantUML syntax to define component structures, which I want to process in an own tool. However, I'd like to avoid having to write a PlantUML parser. Is there some sort of intermediate representation in PlantUML, which I could use for that? It would be perfect to have e.g. a JSON structure which contains all diagram objects and relations among them in a concise way.
I could not find anything in the docs, maybe someone with more insights in the project can help?
As Jean-Marc Volle pointed out, the project github.com/jupe/puml2code allows to process puml files and generate source code in different languages using handlebar templates. Currently the code generation is limited to classes in a puml file.
I have used puml2code as a starting point for a new project github.com/robbito/puml2json, which simplifies the process a bit, as it doesn't require handlebar. Json ist directly generated from the PlantUML code. puml2json currenlty also only supports a subset of PlantUML.

Using InctantUI to create dynamic user interfaces in Codenameone

I have been struggling with creating Dynamic user interfaces or forms in Codenameone. InstantUI will work with PropertyBusinessObjects. However, the current documentation assumes that these will be defined a priori. I want a situation where I can go from a map to InstantUI. My real use case is to create an InstantUI from a JSONObject. IS this possible? If so how?
There is currently no support for that in the InstantUI class as the PropertyBusinessObject contains far more information than just key/value pairs e.g. it contains type information, labels, constraints etc.
So no that's not possible. However, you can look at the source of InstantUI and use that as a starting point to create your own implementation that doesn't require these things or fetches them from a different source.

Why choosing for an Object Parser instead of an Array Parser

I'm parsing a XML-file into objects but I'm wondering why,
I would haven't choosed an Array Parser instead of an Object Parser?
Does it have more pro's than an Array parser or less contra's?
is it more flexible and expansible?
Kind regards
I think it all depends on the input data. If you application needs a lot of simple configuration files storing the state/setup of a single object, then there would be less overhead in handling the parser's output if you use ObjectParser.
But once you have a scenario when you need to store actual object collections (e.g., a list of independent GUI controls to be attached somewhere) and you read such collections often enough, then, if you still use ObjectParser you would have to invent a "collection" class and convert this list to the actual array.

Resources