Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从json到对象的非典型反序列化_Java_Json - Fatal编程技术网

Java 从json到对象的非典型反序列化

Java 从json到对象的非典型反序列化,java,json,Java,Json,我有一个不典型的班级: * @generated public class Something { protected EList<A> a; //generated from eclipse emf ... (only Strings and Ints) } 对于String,int-itp,一切正常。但我对Elist类型有个问题。如何反序列化此列表?我真的建议使用gson。在任何情况下,您都需要编写一个自定义适配器来处理任何不属于标准Java语言的复杂类。 publ

我有一个不典型的班级:

* @generated

public class Something 
{
protected EList<A> a;  //generated from eclipse emf

 ... (only Strings and Ints)

}

对于String,int-itp,一切正常。但我对Elist类型有个问题。如何反序列化此列表?

我真的建议使用gson。在任何情况下,您都需要编写一个自定义适配器来处理任何不属于标准Java语言的复杂类。
public static void main(String args[]) throws JsonParseException,
                JsonMappingException, IOException {

         AMD converter = new AMD ();

         String json = "{\"id\": \"2\",\ ... \"art\": [ null ]}";

         // converting JSON String to Java object
         A a = (A) converter.fromJson(json);
         System.out.println(a);
   }

   public Object fromJson(String json) throws JsonParseException,
                JsonMappingException, IOException {

         A a = new ObjectMapper().readValue(
                       json, A.class);

         return a;
   }