Questions tagged [json-view]

85 questions
4
votes
0 answers

Choose JsonView to serialize HttpResponse at runtime

We have a spring backed resteasy REST API implementation using Jackson. I want to decide at runtime (inside my resource class) which JsonView should be used to serialize the HttpResponse. @Path("/foos") public FooResource { @GET …
James
  • 11,654
  • 6
  • 52
  • 81
4
votes
1 answer

How to override @JsonView in jersey resource methods

I have some jersey resource methods set with @JsonView annotation in order to filter the fields returned in the response. I'd like to be able in some cases to override the JsonView set in the annotation with another one or sometimes completely…
Alex Kubity
  • 364
  • 4
  • 16
3
votes
2 answers

Execution optimizations have been disabled for task ':compileGsonViews'

We recently upgraded our project from Grails 3 to 5.1.1. Actually, it was not really an upgrade but rather a migration. We ended up creating a fresh project with 5.1.1 and migrated all of our code into it. Everything is currently working with an…
Shurik Agulyansky
  • 2,607
  • 2
  • 34
  • 76
3
votes
1 answer

How to Apply @JsonView only for children of a Object with Spring RestController - serialization?

I have this case: public class Project{ private long id; private List users; // other properties and getter setter etc } public class User{ @JsonView(MinimalUser.class) private long id; …
Luxusproblem
  • 1,913
  • 11
  • 23
3
votes
1 answer

Springboot swagger with JsonView

It's possible to integrate the swagger with @JsonView? I have one model that I use the @JsonView to return only a few fields, but the swagger-ui shows the hole model. This is my model: public class Intimacao extends EntityBase { @Embedded …
Fabio Ebner
  • 2,613
  • 16
  • 50
  • 77
3
votes
2 answers

Customizing JSON output CakePHP

$user = $this->User->find( 'all' ); $this->set( 'users', $user ); I have this code in my controller. In my view I have this. echo json_encode( compact( 'users' ) ); It outputs json like this { "users": [{ "User": { …
Drew H
  • 4,699
  • 9
  • 57
  • 90
2
votes
1 answer

Conditional @JsonView within controller method

I have a controller method annotated with @JsonView. The current requirement is to have this same method return the response using a different JsonView if the userId given in parameter matches the authenticated user. How to achieve this knowing that…
khazouss
  • 55
  • 8
2
votes
0 answers

How do I get @JsonView to work with MapStruct

So I am migrating all of my controllers to using a DTO object as previously they used the persistence objects. I have chosen to make use of MapStruct for this. My problem is I have seemingly lost the ability to apply @JsonView to this response, as…
Mark Brown
  • 167
  • 2
  • 12
2
votes
0 answers

Jackson ObjectMapper how to use a JsonView when reading a POJO to a JsonNode

So I have a strange issue where jackson's ObjectMapper has a valueToTree(someObject) method that takes a POJO and outputs a JsonNode. However, the object I have has a bajillion fields on it that should not be serialized when doing this, and…
K. M
  • 867
  • 1
  • 8
  • 17
2
votes
1 answer

@JsonView: different perspectives

I'm coding a Spring Web Service, using Jackson by default. I'm using @JsonView to indicate which property I need to be parsed to my JSON object. So, the problem is: Many objects are used in different classes, but not exactly all its properties, for…
psi_
  • 65
  • 5
2
votes
0 answers

Spring HATEOAS with nested resources and JsonView filtering

I am trying to add HATEOAS links with Resource<>, while also filtering with @JsonView. However, I don't know how to add the links to nested objects. In the project on on Github, I've expanded on this project (adding in the open pull request to make…
Don Subert
  • 2,636
  • 4
  • 27
  • 37
2
votes
0 answers

spock test cases for controller with @JsonView returns empty content

I am writing spock test cases for testing my Spring mvc rest webservices. When I have @JsonView as part of the controller method, the response content is empty. Removing @Jsonview returns the data How do I mock the data with @JsonView in the below…
2
votes
1 answer

Grails JSON Views - default date rendering

When using Marshallers, I could use something like: JSON.registerObjectMarshaller(Date) { return it?.format("yyyy-MM-dd'T'HH:mm:ss") } and it would make all Date objects render to JSON with that format. Is there an equivalent I can use with…
Anonymous1
  • 3,877
  • 3
  • 28
  • 42
2
votes
1 answer

How can a @JsonView working with jersey

I want to return different fields with different views for one object. But it always return all the fields. I created 3 different views: public class Views { public static class PublicView { } public static class ExtendedPublicView extends…
ZhangPang
  • 31
  • 1
  • 4
2
votes
1 answer

JSON is invalid (JSONview), but I don't see how

OK, I've been going nuts with this. I'm outputting a JSON from PHP, and the JSON View extension, for both Chrome and Firefox, is claiming it's invalid. Both extensions work correctly on JSON View's example, so it seems likely that there actually is…
KRyan
  • 7,308
  • 2
  • 40
  • 68