Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse a json file into a java POJO class using GSON

Tags:

java

json

gson

I am using GSON to parse a JSON file and i want to map this JSON object to a POJO class. The problem is the property name in JSON doesn't have camel-case but my java POJO object having camel-case property name.

Is there any idea without having any performance hit?

Eg: attribute name in JSON file is 'OrderNumber', But in my POJO class , Instead ordernumber, i have 'salesNumber' as attribute name. Now how can we map that OrderNumber from JSON to salesNumber of POJO class?

Thanks in advance!

like image 383
user1570345 Avatar asked Aug 06 '26 13:08

user1570345


1 Answers

You can use @SerializedName annotation in this case.

private class SomeObject {

  @SerializedName("OrderNumber") 
  private String salesNumber;

}
like image 181
andrew Avatar answered Aug 09 '26 03:08

andrew