Skip to content
Advertisement

Using JAVA Reflection how to create custom JSON object mapping

I have a json Object in the below format, I need to assign the values from Json to java object, But the label name in JSON and class is different.

JavaScript

I wanted to implement the custom object mapper using Java reflection. the mapping is as below, But I am not getting idea to implement this, Any valuable suggestion or usage of external api would help me to achieve the scenario.

Json Object name Jave Class object Name FirstName ———- Name1 LastName ———- Name2
Address.type ——- Address class type Address.street —– Address class data

Advertisement

Answer

You would need reflexion if you receive json data with same structure with properties names changing, for example :

JavaScript

In your case, it rather look like a property name matching issue, you can annotate your java pojo like that :

JavaScript

Finally you can deserialize your json object using standard Jackson library :

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement