-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using JsonValue and JsonFormat on one field does not work as expected #2822
Comments
I think that this should work, ideally. So sounds like a real bug. Thank you for reporting this! |
I can reproduce this, and will see if use of In the meantime if anyone is looking for work-arounds, forcing serialization as String for all
|
Ah ha. |
Good news: I fixed the problem with annotation propagation. One downside: I realized that the annotation placement to use must be bit different -- it has to be next to actual property, and not within definition next to private static class A {
// Needs to be here as this is the actual property through which access occurs
@JsonFormat( shape = Shape.STRING )
private final B b;
public A( final String description, final B b ) {
this.description = description;
this.b = b;
}
}
private static class B {
@JsonValue
// CANNOT be here, alas
private final BigDecimal value;
public B( final BigDecimal value ) {
this.value = value;
}
} and with that, fix works. Supporting alternative placement would be nice but I am not sure how feasible it is -- conceptually that would be logical: annotation on |
Hi,
We tried to use the both annotations
JsonValue
andJsonFormat
on one field, but the serialization does not work as expected. Assume following code:Note that the field
value
ofB
has two annotations. The resulting string isWe would expect the value of
B
beeing written as a string, so we would expectIf we remove the
JsonValue
annotation, we get the correct (but nested) valueIs this a bug or the correct behaviour?
Thank you and best regards
Nils
Edit: We are using Jackson 2.11.2.
The text was updated successfully, but these errors were encountered: