A
A
al_gon2016-11-09 15:18:51
Java
al_gon, 2016-11-09 15:18:51

Make attributes in JSON required?

Does anyone know an elegant way to make certain attributes in JSON mandatory.
Rather, it is inconsistent with the nature of JSON. Forgive me frontend!
But in practice, config is stored in JSON and you don't want to do a check in every component that uses this mechanism. A is more likely at once at a deserialization.
Yes:
1) Jackson 2.6

@JsonCreator
    public MyClass(@JsonProperty(value = "x", required = true) Integer x, @JsonProperty(value = "value_y", required = y) Integer totalCount) {
...
}

2) Own adapted, working version: uses GSON and custom annotations.
Maybe there is something that makes it more elegant and out of the box?
A link or even a name will already help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Kosarev, 2016-11-09
@al_gon

You can try JSON validation with a schema.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question