I'll start directly with my question and later on I give more background information.
Simple: I hava a LinkedHashMap<String, String>
and it represents a specific object.
What is the best way to convert it to that object?
I know that you can use generics to get through all elements and set the fields, but what is whit nested objects?
Background: I have a JAX-RS service that consumes JSON objects. My service handles different kind of objects and just represents an interface. So I don't know which objects are coming from outside and which program is using my service.
At runtime I get the information via @Inject
on my interface. The JAX-RS service stores the data from the client in an untyped Object and its done automatically (thats the LinkedHashMap<String, String>
).
With my interface I want to provide a method like setObject
and parameter should be a object of that type. I can handle all of this, but not the part where I convert the Object LinkedHashMap<String, String>
to that specific object.
Example Structure: Target Objects could like that
public class Document {
private String title;
private String id;
private int version;
}
The LinkedHashMap
looks like that
{title=some title, id=1, version=1}