0

I created a small spring boot project to retrieve a sample object from mongoDb via spring data rest which contains a Seq (vavr collection). Immediately after booting the app it doesn't work. At first I have to do an insertion and afterwards it works to call teh repo's rest endpoint.

Error msg from log

Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Couldn't find PersistentEntity for type class io.vavr.collection.List$Cons!; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Couldn't find PersistentEntity for type class io.vavr.collection.List$Cons! (through reference chain: org.springframework.hateoas.PagedResources["_embedded"]->java.util.Collections$UnmodifiableMap["myEntities"]->java.util.ArrayList[0]->org.springframework.data.rest.webmvc.json.PersistentEntityJackson2Module$PersistentEntityResourceSerializer$1["content"]->de.spring.demo.entity.MyEntity["myList"])

It sounds like some mappers have to be injected which are automatically injected after inserting a new entry (or some lazy loading maybe...)

A sample can be found here: https://github.com/renne-b/spring-rest-demo

It would be great to get a hint what's missing.

some details:

  • latest spring boot milestone: 2.0.0.M3
  • I registered VavrModule at ObjectMapper
  • @EnableMongoRepositories(basePackages = "for my path to classes")
RenneB
  • 41
  • 5

1 Answers1

1

I update your project with

  • Spring boot 2.0.0.RELEASE
  • EmbeddedMongo de.flapdoodle.embed:de.flapdoodle.embed.mongo:2.0.3 / 3.2.2:Windows:B64
  • Fix JSON mapping

And after that request curl http://localhost:8080/myEntities executed without problems:

{
  "_embedded" : {
    "myEntities" : [ ]
  },
  "_links" : {
    "self" : {
      "href" : "http://localhost:8080/myEntities{?page,size,sort}",
      "templated" : true
    },
    "profile" : {
      "href" : "http://localhost:8080/profile/myEntities"
    }
  },
  "page" : {
    "size" : 20,
    "totalElements" : 0,
    "totalPages" : 0,
    "number" : 0
  }
}

After add 2 entities:

{
  "_embedded" : {
    "myEntities" : [ {
      "foo" : "bar1521033137701",
      "myList" : {
        "content" : [ "bla" ]
      },
      "_links" : {
        "self" : {
          "href" : "http://localhost:8080/myEntities/5aa91fb1bec7c7169c9b5943"
        },
        "myEntity" : {
          "href" : "http://localhost:8080/myEntities/5aa91fb1bec7c7169c9b5943"
        }
      }
    }, {
      "foo" : "bar1521033145175",
      "myList" : {
        "content" : [ "bla" ]
      },
      "_links" : {
        "self" : {
          "href" : "http://localhost:8080/myEntities/5aa91fb9bec7c7169c9b5944"
        },
        "myEntity" : {
          "href" : "http://localhost:8080/myEntities/5aa91fb9bec7c7169c9b5944"
        }
      }
    } ]
  },
  "_links" : {
    "self" : {
      "href" : "http://localhost:8080/myEntities{?page,size,sort}",
      "templated" : true
    },
    "profile" : {
      "href" : "http://localhost:8080/profile/myEntities"
    }
  },
  "page" : {
    "size" : 20,
    "totalElements" : 2,
    "totalPages" : 1,
    "number" : 0
  }
}