1. Gson converts json objects into java objects through reflection
import com.google.gson.Gson; public class JsonFormat { //将json字符串转换为java对象 public void jsonToJava(String json_str, Object obj){ Gson gson = new Gson(); obj = gson.fromJson(json_str, obj.getClass()); } }
2.Generation of gson
Through new gson(): all default configurations are used
Through JsonBuilder: customize some configuration options, version support, output , customized serialization, deserialization and constructors, etc.
Builder pattern: A type of designer pattern that separates the construction of a complex object from its representation.
The above is the detailed content of What is the principle of converting json string to java object. For more information, please follow other related articles on the PHP Chinese website!