简体   繁体   中英

How do I parse an value that can be an object or a string - Java - Jackson

I am using Jackson to deserialize some xml . My xml has a value that can be an object or a string. Here is my xml

<FormFieldHidden name="RequestTime">
  <DefaultValue>
    <DataSourceName>DataSourceCurrentTime</DataSourceName>
  </DefaultValue>
</FormFieldHidden>
<FormFieldHidden name="TradPtnrID">
  <DefaultValue>043355932</DefaultValue>
</FormFieldHidden>

Here is my java:

@JsonIgnoreProperties(ignoreUnknown = true)
public class Forms {

    public Form form;

    public Forms() {
      form = new Form();
    }

    public static class Form extends Asset {
      public String version;
      public String description;

    public List<Section> sections;

    }

    public static class Section {
      public String label;
      public int totalColumns;
    public List<FormFieldHidden> formFields;
    }

    public static class FormFieldHidden {
      public String defaultValue;
    }
}

How can I pull out the defaultValue whether it is an object or string?

I havent work with Jackson but maybe instanceof will help, in pseudocode

if (value instanceof Class){Class c=value;}
else{String s=value;}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM