Extract a List of values for keys with the same prefix using @JsonPropperty
up vote
1
down vote
favorite
For this JSON:
{"key.a": "a", "key.b": "b"}
I want to load values "a" and "b" to List using @JsonProperty and Jackson. I tried:
@JsonProperty("key.*")
List<String> values;
But it doesn't work. Any thoughts?
java json spring jackson
New contributor
user3751481 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
1
down vote
favorite
For this JSON:
{"key.a": "a", "key.b": "b"}
I want to load values "a" and "b" to List using @JsonProperty and Jackson. I tried:
@JsonProperty("key.*")
List<String> values;
But it doesn't work. Any thoughts?
java json spring jackson
New contributor
user3751481 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
For this JSON:
{"key.a": "a", "key.b": "b"}
I want to load values "a" and "b" to List using @JsonProperty and Jackson. I tried:
@JsonProperty("key.*")
List<String> values;
But it doesn't work. Any thoughts?
java json spring jackson
New contributor
user3751481 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
For this JSON:
{"key.a": "a", "key.b": "b"}
I want to load values "a" and "b" to List using @JsonProperty and Jackson. I tried:
@JsonProperty("key.*")
List<String> values;
But it doesn't work. Any thoughts?
java json spring jackson
java json spring jackson
New contributor
user3751481 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
user3751481 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
user3751481 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked Nov 8 at 10:08
user3751481
82
82
New contributor
user3751481 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
user3751481 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
user3751481 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
You can use the JsonAnySetter annotation, which will map any unknown Json property, on a setter method:
private List<String> values = new ArrayList<>();
@JsonAnySetter
public void setValues(String key, String value) {
// You can perform a pattern validation on the key if wanted
this.values.add(value);
}
public List<String> getValues() {
return this.values;
}
An alternative solution would be to implement a custom JsonSerializer & JsonDeSerializer as well.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
You can use the JsonAnySetter annotation, which will map any unknown Json property, on a setter method:
private List<String> values = new ArrayList<>();
@JsonAnySetter
public void setValues(String key, String value) {
// You can perform a pattern validation on the key if wanted
this.values.add(value);
}
public List<String> getValues() {
return this.values;
}
An alternative solution would be to implement a custom JsonSerializer & JsonDeSerializer as well.
add a comment |
up vote
0
down vote
accepted
You can use the JsonAnySetter annotation, which will map any unknown Json property, on a setter method:
private List<String> values = new ArrayList<>();
@JsonAnySetter
public void setValues(String key, String value) {
// You can perform a pattern validation on the key if wanted
this.values.add(value);
}
public List<String> getValues() {
return this.values;
}
An alternative solution would be to implement a custom JsonSerializer & JsonDeSerializer as well.
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
You can use the JsonAnySetter annotation, which will map any unknown Json property, on a setter method:
private List<String> values = new ArrayList<>();
@JsonAnySetter
public void setValues(String key, String value) {
// You can perform a pattern validation on the key if wanted
this.values.add(value);
}
public List<String> getValues() {
return this.values;
}
An alternative solution would be to implement a custom JsonSerializer & JsonDeSerializer as well.
You can use the JsonAnySetter annotation, which will map any unknown Json property, on a setter method:
private List<String> values = new ArrayList<>();
@JsonAnySetter
public void setValues(String key, String value) {
// You can perform a pattern validation on the key if wanted
this.values.add(value);
}
public List<String> getValues() {
return this.values;
}
An alternative solution would be to implement a custom JsonSerializer & JsonDeSerializer as well.
edited Nov 8 at 10:30
answered Nov 8 at 10:20
tmarwen
8,38232441
8,38232441
add a comment |
add a comment |
user3751481 is a new contributor. Be nice, and check out our Code of Conduct.
user3751481 is a new contributor. Be nice, and check out our Code of Conduct.
user3751481 is a new contributor. Be nice, and check out our Code of Conduct.
user3751481 is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53205487%2fextract-a-list-of-values-for-keys-with-the-same-prefix-using-jsonpropperty%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password