Skip to content

@JsonUnwrapped ignored with (embedded) CollectionModel and HAL Forms #968

@toedter

Description

@toedter

To create REST resources with a list of embedded resources I use a pattern like

@JsonUnwrapped
CollectionModel<EntityModel<Movie>> movies;

As an example:

@Data
public class DirectorRepresentationModel extends RepresentationModel {
    private long id = 1;
    private String name = "Steven Spielberg";

    @JsonUnwrapped
    CollectionModel<EntityModel<Movie>> movies;

    public DirectorRepresentationModel() {
        Movie movie1 = new Movie();
        movie1.setId("1");
        movie1.setTitle("ET");

        Movie movie2 = new Movie();
        movie2.setId("2");
        movie2.setTitle("Jaws");

        EntityModel<Movie> p1 = new EntityModel<>(movie1);
        EntityModel<Movie> p2 = new EntityModel<>(movie2);

        movies = new CollectionModel<>(Arrays.asList(p1, p2));
    }
}

When setting the hypermedia configuration to HAL, it is rendered as I would expect:

{
  id: 1,
  name: "Steven Spielberg",
  _embedded: {
    movieList: [
      {
          id: "1",
          title: "ET"
      },
      {
           id: "2",
           title: "Jaws"
      }
     ]
   }
}

But when setting the hypermedia configuration to HAL_FORMS, the @JsonUnwrapped does not apply:

{
  id: 1,
  name: "Steven Spielberg",
  movies: {
    _embedded: {
       movieList: [
         {
             id: "1",
             title: "ET"
         },
         {
              id: "2",
              title: "Jaws"
         }
        ]
     }
  }
}

IMHO HAL_FORMS should render this exactly like HAL does.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions