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

萝らか妹 提交于 2019-12-12 09:55:02

问题


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!


回答1:


You can use @SerializedName annotation in this case.

private class SomeObject {

  @SerializedName("OrderNumber") 
  private String salesNumber;

}


来源:https://stackoverflow.com/questions/29383204/how-to-parse-a-json-file-into-a-java-pojo-class-using-gson

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!