Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>If you can modify the class being wrapped</strong>, then you can use Jackson's @JsonView annotation, here is the <a href="http://wiki.fasterxml.com/JacksonJsonViews" rel="nofollow">full tutorial</a>.</p> <p>Step 1: create interfaces like so:</p> <pre><code>public class MyJsonViews { public static class Small { } public static class Medium extends Small { } public static class Large extends Medium { } } </code></pre> <p>Step 2: annotate properties (or methods) in your POJOs:</p> <pre><code>public class Wrapper { @JsonView(MyJsonViews.Small.class) private String name; @JsonView(MyJsonViews.Medium.class) private Wrapped wrapped; // getters and setters } public class Wrapped { @JsonView(MyJsonViews.Small.class) private String someField; @JsonView(MyJsonViews.Medium.class) private String anotherField; // getters and setters } </code></pre> <p>Step 3: serialize using the new views:</p> <pre><code>ObjectMapper objectMapper = new ObjectMapper(); // important: this excludes all fields without @JsonView from being serialized objectMapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, false); String json = objectMapper.writerWithView(SMyJsonViews.mall.class).writeValueAsString(wrapper); </code></pre> <p>Your JSON will now contain just the fields annotated with @JsonView(MyJsonViews.Small.class).</p> <p><strong>If you cannot modify the class being wrapped</strong>, then you could use the Filter approach, described <a href="http://wiki.fasterxml.com/JacksonFeatureJsonFilter" rel="nofollow">here</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload