尝试将我的对象转换为Hashmap时发生IllegalArgumentException

时间:2019-01-23 01:04:50

标签: java exception serialization hashmap jackson

我有一个物体。我正在尝试将我的对象转换为hashmap。如下所示:

@XmlRootElement
@XmlType(propOrder = {"isIdAvail","isFrndAvail","otherDetails"})
@XmlAccessorType(XmlAccessType.FIELD)
public class MyObject implements Serializable {
    private boolean isIdAvail;
    private boolean isFrndAvail;
    private List<OtherDetails> otherDetails;

    //getters and Setters
}

我将上述对象作为响应,我正尝试将其转换为Map,如下所示:

 HashMap<String, Object> result;
 result = new ObjectMapper().setDefaultPropertyInclusion(                    
 JsonInclude.Value.construct(Include.ALWAYS, 
 Include.NON_NULL)).convertValue(response, HashMap.class);

上述程序的输出为:

{
   "isIdAvail": true,
   "isFrndAvail": true,
   "otherDetails": [
               {}
    ]
}

当尝试将上述对象响应转换为Hashmap时,即使我有NON_NUL,我也会收到以下异常:

java.lang.IllegalArgumentException: (was java.lang.NullPointerException) (through reference chain: com.myproject.org.bump.tref.model.FullDetailsResponse["fullOtherDetails"]->java.util.ArrayList[0]->com.myproject.org.bump.tref.model.FullOtherDetails["otherDetails"]->java.util.ArrayList[0]->com.myproject.org.bump.tref.model.FullDetailsResponse["otherLineId"])

在这里,任何建议都非常有用,因为浪费了很多其他类似的线程,其中包括我已经在做的了NON_NULL。 提前致谢。请问有人有什么想法吗?

0 个答案:

没有答案