You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
FEATURE: Allow to specify a Json View to serialize a property of an object #132
Currently it's not possible to serialize the property of an object specifying a Json view. Please create a new @JsonUseView annotation to be able to specify a view used to serialize the property.
public class Company {
@JsonView(View.Basic.class)
private Long id;
@JsonView(View.Basic.class)
private String name;
private String extraData;
private String sensitiveData;
private String privateData;
...
}
public class User{
private Long id;
private String name;
@UseJsonView(View.Basic.class)
private Company company;
...
}
Or create a new set of annotations that allow this feature. For example:
@JsonViews(views={
@View(name="basic", fields=["id", "name"]),
@View(name="otherView", fields=["id", "name", "extraData"]),
})
public class Company {
private Long id;
private String name;
private String extraData;
private String sensitiveData;
private String privateData;
...
}
public class User{
private Long id;
private String name;
@UseJsonView("basic")
private Company company;
...
}
changed the title [-]FEATURE: Enable to serialize a property using Json views feature[/-][+]FEATURE: Allow to specify a Json View to serialize a property[/+]on Mar 27, 2018
changed the title [-]FEATURE: Allow to specify a Json View to serialize a property[/-][+]FEATURE: Allow to specify a Json View to serialize a property of a object[/+]on Mar 27, 2018
changed the title [-]FEATURE: Allow to specify a Json View to serialize a property of a object[/-][+]FEATURE: Allow to specify a Json View to serialize a property of an object[/+]on Mar 27, 2018
@jwang0512 If there was an update, it'd be here. I don't think anyone is implementing such support -- support would be added via jackson-databind repository, beyond addition of a new annotation here.
I am not sure implementing this is practical, either, since it would clash with per-call View setting. But whoever wanted to implement that would need to figure it out.
Activity
[-]FEATURE: Enable to serialize a property using Json views feature[/-][+]FEATURE: Allow to specify a Json View to serialize a property[/+][-]FEATURE: Allow to specify a Json View to serialize a property[/-][+]FEATURE: Allow to specify a Json View to serialize a property of a object[/+][-]FEATURE: Allow to specify a Json View to serialize a property of a object[/-][+]FEATURE: Allow to specify a Json View to serialize a property of an object[/+]lenxeon commentedon Feb 4, 2020
what the content about UseJsonView ?
jwang0512 commentedon Apr 8, 2025
Really need this one, an update or any other alternative ways please?
cowtowncoder commentedon Apr 8, 2025
@jwang0512 If there was an update, it'd be here. I don't think anyone is implementing such support -- support would be added via
jackson-databindrepository, beyond addition of a new annotation here.I am not sure implementing this is practical, either, since it would clash with per-call View setting. But whoever wanted to implement that would need to figure it out.
jwang0512 commentedon Apr 9, 2025
Thanks for your reply @cowtowncoder
I want this because I need to serialize different fields in different situations. Here is my example
and here is my implementation. for anyone who need this: