小编Flo*_* T.的帖子

杰克逊反序列化具有多个名称的枚举

我在反序列化具有多个名称的枚举时遇到问题。下面是一个例子:Info 是一个 Java 类,它内部有一个具有多个名称的枚举:

public class Info {
    //...
    private ContainerFormat format;
}

// ContainerFormat.java:

public enum ContainerFormat {
    //  ....
    MP4("mp4", "mpeg4"),
    UNKNOWN("null");

    private String name;
    private List<String> others;

    ContainerFormat(String name) {
        this.name = name;
    }

    /** The service does not always return the same String for output formats.
     * This 'other' string fixes the deserialization issues caused by that.
     */
    ContainerFormat(String name, String... others) {
        this.name = name;
        this.others = new ArrayList<String>();
        for (String other : others) { …
Run Code Online (Sandbox Code Playgroud)

java enums json jackson deserialization

4
推荐指数
2
解决办法
6727
查看次数

标签 统计

deserialization ×1

enums ×1

jackson ×1

java ×1

json ×1