0

I know similar questions have been asked before, but they did not resolve my particular scenario.

I am using jackson to bind json to pojo object. The problem is that the Json result will sometimes be a single value:

attributes: [
    {
        name: "IDs",
        value: [
            76715
        ]
    },
    {
        name: "Updated",
        value: false
    },
    {
        name: "Merged",
        value: false
    },
    {
        name: "Source",
        value: "db"
    }
]

My question is, how do I account for this in my attribute object?

I tried string, then tried an array then tried to combine them.

private List value = new ArrayList();

public List getValue() {
    return value;
}

public void setValue(List value) {
    this.value = value;
}

public void setValue(String value) {
    this.value.add(value);
}

So far nothing has worked for all the possibilities for "value".

1 Answer 1

1

An Attribute class which define value as Object will do the job:

public static class Attribute {
  private String name;
  private Object value;

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public Object getValue() {
    return value;
  }

  public void setValue(Object value) {
    this.value = value;
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Also, when you get the value, you can use instanceof to determine what you have.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.