Conversion of JSON to Java Pojo using MapStruct - mapstruct

How to convert an incoming JSON object structure to Java Pojo using mapstruct?
The incoming JSON response object structure might be different as per the configuration.
Thanks.

For a moment MapStruct hasn't this functionality. I know, that they are working on mapping from object to JSON. Mb they are also working on opposite conversion.

Related

To use the confluent schema registry and avro serializer in the spring application, how to do for json data input

Currently, I have used spring cloud stream github example, however I do not know how to transfer the manually typed objects into json format by providing from the existing json data. I can infer the avro schema using some tool from json data. However the problem is I do not want to use POJOs that is inferred from class in import using avro schema instead I want to use the existing json data. I am also confused about the application/json part, when I am using
curl -X POST, maybe is there a way to feed the data in http request(add annotations in the send message part). Also, give an explanation of #ResquestMapping, and #Enablebinding, #StreamListener, when to use them.
To start off, you'd have to define a producer using the KafkaAvroSerializer rather than some StringSerializer or JSON one
from the existing json data
You'd use a from the existing json data like Jackson or Gson to take JSON to a POJO by parsing it.
the problem is I do not want to use POJOs that is inferred from class
POJO defines classes. They're not inferred
using avro schema instead I want to use the existing json data.
JSON and Avro are different formats. You'd have to use some tool to translate them or manually parse JSON yourself and create an Avro record
I am also confused about the application/json part, when I am using curl -X POST, maybe is there a way to feed the data in http request(add annotations in the send message part
Yes, headers define extra metadata in the request
curl -H 'Content-Type:application/json`
#StreamListener, when to use them
When you're consuming events, not sending them

Building Rule Based on JSON Object

Currently, we are exploring CodeEffects for our one of the rule engine proposal.
We have a dynamic type which is a JSON string. During runtime, we need to apply the rule for JSON using CodeEffects. Is it support for FlexSource or any other possibility.
You need to serialize your Json string into a .NET object, fill it with data if needed, and pass that object to the Evaluator together with your rule for evaluation. The FlexSource is designed specifically to support this kind of scenarios. Download the FlexSource demo project from Code Effects website and replace the XML data file used there as the source object with your Json.

google-cloud-datastore java client: Is there a way to infer schema and/or retrieve results as Json?

I am working on datastore datasource for apache-spark based on spark datasource V2 api. I was able to implement using hard-coded single entity but couldn't generalize it. Either I need to infer entity schema and translate entity record into Spark Row or read entity record as json and let the user translate into scala product (datastore java client is REST based so the payload is being pulled as json). I could see "entity.properties" as json key-values from within IntelliJ debugger which includes everything I need (column name, value, type etc.) but I can't use entity.properties due to access restrictions. Appreciate any ideas.
fixed by switching to low level API https://github.com/GoogleCloudPlatform/google-cloud-datastore
full source for spark-datastore-connector https://github.com/sgireddy/spark-datastore-connector

How to convert JSON into Scala class (NOT Case class), and then populate set of case classes from that big class

I am building an application using Scala 2.10, Salat and Play frmework 2.1-RC2 (will upgrade to 2.1 release soon) and MongoDB.
This is a faceless application where JSON web services are exposed for consumers. Up until now JSON was converted into Model object directly using Play's Json API and implicit converters. I have to refactor some case classes to avoid 22 tuples limit and now instead of flat case class I'm now refactoring to have an embedded case(and embedded MongoDB collection).
Web service interface should remain same where client should still be passing in JSON data as they were before in a flat structure but application needs to map them into proper case class(es) structure. What's the best way to handle this kind of situation. I fear of writing a lot of conversion code <-> Flat JSON <-> complex case class structure <-> from complex case classes to flat JSON output again.
How would you approach such a requirement? I assume case class 22 tuple limit may have had been faced by many others to handle this kind of requirements? How would you approach this
The Play 2.1 json library relies heavily on combinators (path1 and path2). These combinators all have the same 22 restriction. That gives you two options:
Don't use combinators and construct your objects the hard way: path(json) will give you the value at that point in the path. Searching for 'Accessing value of JsPath' at ScalaJsonCombinators will give more examples.
First transform the json into a structure that does not have more than 22 values in a single object and then use the normal combinators. More information about transforming can be found here: ScalaJsonTransformers

Using RPC serialization/deserialization mechanism built in GWT

I am developing GWT offline application using HTML5 Local Storage. I would like to cache/store the transfer objects using com.google.gwt.storage.client.Storage (introduced in version 2.3). But the problem is that as for now (version 2.3) the Storage can only save the string values.
Is there any possibility to use GWT's built in rpc serialization/deseralization mechanism from client side code? So that I will be able to serialize transfer objects and store them in Local Storage and retrieve them when needed and deserialize the content.
GWT Docs have this to say:
Local Storage is String Storage
HTML5 local storage saves data in
string form as key-value pairs. If the data you wish to save is not
string data, you are responsible for conversion to and from string
when using LocalStorage. For proxy classes used with the GWT
RequestFactory, you can use RequestFactory#getSerializer() to do
string serializing. For non-proxy objects, you could use JSON
stringify and parse.
EDIT:
RequestFactory#getSerializer() returns an implementation of ProxySerializer. But
ProxySerializer Serializes graphs of EntityProxy objects. A
ProxySerializer is associated with an instance of a ProxyStore when it
is created via RequestFactory.getSerializer(ProxyStore).
So you cannot use it to serialize arbitrary objects. Only EntityProxy objects can be serialized this way. GWT documentation does not mention any method for doing such serialization for non-EntityProxy objects, so I think it is safe to assume that there is no ready-made solution for doing this so far. For non-EntityProxy objects, GWT docs (quoted above) recommend using JSON serialization.