0

I have a small module that should only contain the resource model of my REST service. I want to create a test in this module to ensure that the resource model serializes and deserializes appropriate HAL format.

I have a single test and this is the configuration:

@RunWith(SpringRunner::class
@SpringBootTest
@AutoConfigureJsonTesters
class MyTest {

    @Autowired
    private lateinit var collectionTester: JacksonTester<Resources<Entity>>

 ....
}

and a very simple configuration

@SpringBootConfiguration
class TestConfig

When calling collectionTester.write on a list of Entity (which extends ResourceSupport) I don't get an _embedded field, instead I get

{"links":[],"content":[...]}

which is not HAL format.

How can I force @AutoConfigureJsonTesters to give me a JacksonTester with an ObjectMapper configured for HAL?

Spring Boot 2.0.0.RELEASE

Thanks!

HughWPHamill
  • 58
  • 10

1 Answers1

0

The auto-configured JacksonTester will use the context’s ObjectMapper which won’t have any of the Spring HATEOAS stuff configured on it. You might be better creating a JacksonTester yourself and passing it an appropriately configured ObjectMapper to use.

I believe Spring HATEOAS has a module that it applies to the ObjectMapper to configure it. If you get stuck with that, asking in gitter/spring-projects/spring-data is probably your best bet as Spring HATEOAS is maintained by the Data team due to it being used by Spring Data REST.

xiaohugod
  • 51
  • 1
  • 1