-
Notifications
You must be signed in to change notification settings - Fork 322
Closed
Description
hi!
I found another problem this time during testing.
Controller:
@QueryMapping
suspend fun people(): Flow<PersonResponse> {
return service.getAllPeople().map {
PersonResponse(
it.id!!,
it.firstName,
it.lastName,
it.createdAt!!
)
}
}
Test:
@Test
fun `get all persons`() {
val person = Person(
UUID.randomUUID(),
firstName = "Test",
lastName = "Test",
createdAt = LocalDateTime.now()
)
val personResponse = PersonResponse(
person.id!!,
person.firstName,
person.lastName,
person.createdAt!!
)
coEvery { personService.getAllPeople() }.answers { flowOf(person) }
graphQlTester.documentName("getAllPeople")
.execute()
.path("people")
.entityList(PersonResponse::class.java)
.hasSize(1)
.contains(personResponse)
}
query:
query {
people {
id, firstName, lastName, createdAt
}
}
error:
java.lang.IllegalArgumentException: Cannot construct instance of `com.example.backendgraphql.person.response.PersonResponse` (no Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
at [Source: UNKNOWN; byte offset: #UNKNOWN] (through reference chain: java.util.ArrayList[0])
com.jayway.jsonpath.spi.mapper.MappingException: java.lang.IllegalArgumentException: Cannot construct instance of `com.example.backendgraphql.person.response.PersonResponse` (no Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
at [Source: UNKNOWN; byte offset: #UNKNOWN] (through reference chain: java.util.ArrayList[0])
at app//com.jayway.jsonpath.spi.mapper.JacksonMappingProvider.map(JacksonMappingProvider.java:58)
at app//com.jayway.jsonpath.internal.JsonContext.convert(JsonContext.java:121)
at app//com.jayway.jsonpath.internal.JsonContext.read(JsonContext.java:98)
at app//org.springframework.graphql.test.tester.DefaultGraphQlTester$ResponseDelegate.read(DefaultGraphQlTester.java:229)
at app//org.springframework.graphql.test.tester.DefaultGraphQlTester$DefaultPath.entityList(DefaultGraphQlTester.java:395)
at app//com.example.backendgraphql.person.PersonControllerTest.get all persons(PersonControllerTest.kt:44)
This happened when I use data class for response object, when I use record from java I get :
java.lang.IllegalArgumentException: Java 8 date/time type `java.time.LocalDateTime` not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling
at [Source: UNKNOWN; byte offset: #UNKNOWN] (through reference chain: java.util.ArrayList[0]->com.example.backendgraphql.person.PersonResponse["createdAt"])
com.jayway.jsonpath.spi.mapper.MappingException: java.lang.IllegalArgumentException: Java 8 date/time type `java.time.LocalDateTime` not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling
at [Source: UNKNOWN; byte offset: #UNKNOWN] (through reference chain: java.util.ArrayList[0]->com.example.backendgraphql.person.PersonResponse["createdAt"])
at app//com.jayway.jsonpath.spi.mapper.JacksonMappingProvider.map(JacksonMappingProvider.java:58)
at app//com.jayway.jsonpath.internal.JsonContext.convert(JsonContext.java:121)
at app//com.jayway.jsonpath.internal.JsonContext.read(JsonContext.java:98)
at app//org.springframework.graphql.test.tester.DefaultGraphQlTester$ResponseDelegate.read(DefaultGraphQlTester.java:229)
at app//org.springframework.graphql.test.tester.DefaultGraphQlTester$DefaultPath.entityList(DefaultGraphQlTester.java:395)
and record looks like that:
public record PersonResponse(
UUID id,
String firstName,
String lastName,
LocalDateTime createdAt
) {
}
And as you can see I have com.fasterxml.jackson.datatype:jackson-datatype-jsr310
Metadata
Metadata
Assignees
Labels
type: enhancementA general enhancementA general enhancement