spring-projects / spring-projects/spring-data-rest

@JsonTypeInfo is missing from Spring Data REST Repositories HAL+JSON output [DATAREST-405]

Open
#782 2 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 31, 2020.

in: repository type: bug
Dominant language
Java
Stars
958
Forks
568
PR merge metrics
No merged PRs in 30d

Description

Hendy Irawan opened DATAREST-405 and commented

Example entity:

@Entity
@Table(
	uniqueConstraints=@UniqueConstraint(name="foursquareid_unique", columnNames="foursquareid")
)
@JsonTypeInfo(use=com.fasterxml.jackson.annotation.JsonTypeInfo.Id.NAME, property="type")
@JsonSubTypes(@com.fasterxml.jackson.annotation.JsonSubTypes.Type(name="Place", value=Place.class))
public class Place {

However there's no type in the HAL+JSON output:

{
    "_links": {
        "next": {
            "href": "http://localhost:8080/places?page=1&size=20"
        },
        "self": {
            "href": "http://localhost:8080/places{?page,size,sort}",
            "templated": true
        },
        "search": {
            "href": "http://localhost:8080/places/search"
        }
    },
    "_embedded": {
        "places": [
            {
                "id": "6454f64a-1d56-49b8-afe6-ce147fa658db",
                "name": "Amanda",
                "sourceUri": "http://id.openrice.com/bandung/restaurant/amanda-brownies-kukus/13468/?s=3",
                "sourceUris": [
                    "http://id.openrice.com/bandung/restaurant/amanda-brownies-kukus/13468/?s=3"
                ],
                "photoFile": "000BXGDAAC4E4F88642BE7l.jpg",
                "menu": "Brownies",
                "menuPhotoFile": "002ZZ6AAFA377F2366945El.jpg",
                "description": "Amanda itu adalah tempat pusat nya brownies kukus\ndan tempat ini memang sudah snagat terkenal banget\ndan sangat cocok untuk dijadikan pembelian untuk oleh-oleh .\n\nKarena memang amanda yakni adalah terkenal dengan brownies kukus nya .\ndan disini memang langsung dari pabrik\njadi tentu nya masih sangat fress banget .",
                "street": "Jl. Ir. H. Juanda No.167, Ir. Haji Juanda (Dago Bawah)",
                "city": "Bandung",
                "phoneNumber": "(022) 92754195 / (022) 2531959\n",
                "categories": [
                    "Bakery & Cake Shop  /  Dating / Couple  /  Family Gathering"
                ],
                "openingHours": "Mon - Sun 10:00 - 21:00 ",
                "priceRange": "Below Rp.30.000\n",
                "mapImageFile": "",
                "lat": null,
                "lng": null,
                "foursquareId": null,
                "_links": {
                    "self": {
                        "href": "http://localhost:8080/places/6454f64a-1d56-49b8-afe6-ce147fa658db"
                    }
                }
            },
...

This happens with Spring Data REST Repository. If I create my own @RestController and return Place object then the type shows up


Affects: 2.1.4 (Dijkstra SR4)

Issue Links:

  • DATAREST-304 Mapping with @JsonTypeInfo not working
    ("duplicates")

3 votes, 4 watchers

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.