Skip to content

Deserialzing using static method for types of a given super class #237

Answered by sentinel0815
sentinel0815 asked this question in Q&A
Discussion options

You must be logged in to vote

I solved this by adding the @JsonCreator annotation to all concrete codestable classes e.g.

    @JsonCreator
    public static GenderCodestable valueOf(final @JsonProperty("code") String code) {
        if (BY_CODE.containsKey(code)) {
            return BY_CODE.get(code);
        } else {
            throw new NoSuchElementException("No GenderCodestable found with the code: " + code);
        }
    }

As the codestable classes are generated and I am able to adjust the generator this seems to be the easiest solution for me in this case.

Replies: 3 comments 6 replies

Comment options

You must be logged in to vote
3 replies
@sentinel0815
Comment options

@pjfanning
Comment options

@sentinel0815
Comment options

Comment options

You must be logged in to vote
2 replies
@sentinel0815
Comment options

@cowtowncoder
Comment options

Comment options

You must be logged in to vote
1 reply
@cowtowncoder
Comment options

Answer selected by sentinel0815
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants