Interesting idea: use `@JsonValue` on `@JsonCreator` argument to imply "Delegating" creator?

18 views
Skip to first unread message

Tatu Saloranta

unread,
May 9, 2021, 3:08:56 PM5/9/21
to jacks...@googlegroups.com
Based on a bug report that I first thought was invalid, I (finally?)
got an idea that seems worth considering -- what if following usage:

--------------
public class MyValue {
public MyValue(@JsonValue List<String> words) {
...
}

@JsonValue
public List<String> asList() { .... }
}

worked as... well, you might except, that is, as an alias for:

public class MyValue {
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
public MyValue(List<String> words) { ... }
}

--------------

WDYT?

This might be even more compact for Kotlin -- or maybe not, I am not
quite sure how annotations are bound from source to underlying
accessors.

-+ Tatu +-
Reply all
Reply to author
Forward
0 new messages