Eric
01/03/2023, 5:03 PMEric
01/11/2023, 6:57 PMapplication.yaml
? for example
spring:
jackson:
kotlin:
null-to-empty-collection: true
null-to-empty-map: true
null-is-same-as-default: true
wrongwrong
01/14/2023, 4:07 PMwrongwrong
01/21/2023, 2:15 AMkotlin-reflect
with kotlinx-metadata-jvm
would benefit jackson-module-kotlin
users on Android
, please let me know.
https://kotlinlang.slack.com/archives/C0B8M7BUY/p1674267151483919wrongwrong
03/19/2023, 3:19 PMwrongwrong
04/26/2023, 8:35 AMjackson-module-kotlin
2.15.0 has been released.
This version contains many important changes.
Feedback and bug reports are welcome.
https://github.com/FasterXML/jackson-module-kotlin/blob/7dd3c74313b6640724672262e8e0d19f0498de43/release-notes/VERSION-2.x#L23-L61
https://mvnrepository.com/artifact/com.fasterxml.jackson.module/jackson-module-kotlin/2.15.0dave08
04/27/2023, 1:27 PMdmcg
05/16/2023, 7:48 AMBrian Estrada
07/10/2023, 12:59 PMwrongwrong
07/17/2023, 4:42 AMMarcus Ilgner
07/25/2023, 1:32 PMdata class DataPoint {
@JsonFormat(
shape = JsonFormat.Shape.STRING,
pattern = "yyyy-MM-dd HH:mm:ss",
timezone = "UTC")
val time: Instant,
}
val mapper = jacksonObjectMapper()
mapper.registerModule(JavaTimeModule())
val dataPoint = DataPoint(time = Instant.parse("2001-09-09T01:46:40Z"))
val encoded = mapper.writeValueAsString(dataPoint)
assertEquals(
"{\"time\":\"2001-09-09T01:46:40Z\"}",
encoded,
)
Unfortunately the encoded value for time
looks like this an object, even though the shape was set to `STRING`:
{
"time": {
"epochSeconds": 1000000000,
"value$kotlinx_datetime": "2001-09-09T01:46:40Z",
"nanosecondsOfSecond": 0
}
}
any ideas?wrongwrong
09/02/2023, 3:31 AMwrongwrong
10/09/2023, 9:42 AMJeffrey Gulbronson
10/20/2023, 3:40 PMjackson-module-kotlin
? I’m trying to get it to deserialize results with the Elasticsearch client, and have registered the Kotlin extension with registerKotlinModule
. Unfortunately it says Cannot construct instance of Foo (no Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
.
When decompiling the class, it actually has two constructors (one private and public), which we’re not seeing in the data classes that do deserialize correctly (those only have one public constructor)Jeffrey Gulbronson
10/20/2023, 3:47 PMinline
class for a field of the data classJeffrey Gulbronson
10/20/2023, 3:56 PMwrongwrong
10/28/2023, 4:19 PMhenrik
11/01/2023, 4:12 PMwrongwrong
11/11/2023, 2:12 PMwrongwrong
11/20/2023, 12:23 PMwrongwrong
12/02/2023, 12:52 PMYonatan Karp-Rudin
12/11/2023, 9:13 AM1.7.x
to version 1.8.x
or above because of serialization value classes inside of a data class.
Let's consider the following example:
@JvmInline
value class Value(val i: Int)
data class Data(val j: Value)
data class Wrapper(val value: Value, val data: Data)
When trying the following code:
val objectMapper = jacksonObjectMapper()
.setPropertyNamingStrategy(PropertyNamingStrategies.SnakeCaseStrategy())
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.registerModule(JavaTimeModule())
val json = """{"i":1,"j":771}"""
val deserialized = objectMapper.readValue<Wrapper>(json)
This code execution ends up with the following error: (no Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
.
This can be resolved by adding an empty constructor to the classes, but it makes very little sense, and I'm afraid that it would be abused by other developers in the codebase... is there any alternative that I can use here to solve the issue?wrongwrong
02/28/2024, 12:27 PMPihentagy
03/14/2024, 2:38 PMPihentagy
06/28/2024, 10:10 AM@JsonSubTypes
by hand, of is there a convenient solution to use the class name?
So how to avoid
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
@JsonSubTypes(
JsonSubTypes.Type(value=MyState1::class, name = "MyState1"),
// ...
// ...
JsonSubTypes.Type(value= MyState99::class, name = "MyState99")
)
abstract class AbstractState
Btw I don't need the class at all, I am just logging to a jsonb field, and will query it directly from db.
So say, I have this hierarchy:
abstract class AbstractState
data class MyState(val text: String)
and all my wish is to put
{
"text": "the text value"
}
to a jsonb field.Johan
09/16/2024, 5:24 PMdata class FooDto(
val myId: MyId = MyId(),
@JsonDeserialize(using = SealedTypeDeserializer::class)
val type: SealedType = TypeA.FOO,
)
🧵 for more info
Having just one of them works fine when deserializing, but together does not work. Any clue?Pihentagy
10/22/2024, 6:39 AM@Bean
@Primary
fun objectMapper(): ObjectMapper = ...
but this objectMapper is not used when persisting an Entity. The entity has a json field, where my custom serializer would be needed. But based on the error message it seems, that hibernate is not using that serializer. How to tell hibernate to use my custom objectMapper for json fields?wrongwrong
12/29/2024, 9:42 AMwrongwrong
01/19/2025, 5:35 AMHarish Pal
02/10/2025, 11:26 AMUnable to Parse JSON.
Request Payload:
{
"eventTypeId": "USR-05 \" "
}
REST Controller
@Produces(MediaType.APPLICATION_JSON)
@Path("/audit/api/1/events")
open class WriteAuditEventResource {
@POST
@Consumes(MediaType.APPLICATION_JSON)
fun writeEvent(eventRequest: AuditEventRequest): Response {
return Response.status(Response.Status.CREATED).build()
}
}
Problem:
1. In HTTP Logs I can see that the escaped backslash is converted to double backslash (making the JSON invalid). Below are the logs:
{
"eventTypeId": "USR-05 \\" "
}
[o.e.jetty.http.HttpParser ] - parseNext s=CONTENT HeapByteBuffer@64870bee[p=273,l=308,c=8192,r=35]={POST /aud... 35\r\n\r\n<<<{\n "eventTypeId": "USR-05 \\" "\n}>>>\x00\x00\x00\x00\x00\x00\x00\x00\x00...\x00\x00\x00\x00\x00\x00\x00}
[o.e.jetty.server.HttpChannel ] - onContent HttpChannelOverHttp@f084976{s=HttpChannelState@4962b62c{s=HANDLING rs=BLOCKING os=OPEN is=IDLE awp=false se=false i=true al=1},r=1,c=false/false,a=HANDLING,uri=//localhost:8686/audit/api/1/events/,age=35} Content@2bcdd012{HeapByteBufferR@793bf03f[p=273,l=308,c=8192,r=35]={POST /aud... 35\r\n\r\n<<<{\n "eventTypeId": "USR-05 \\" "\n}>>>\x00\x00\x00\x00\x00\x00\x00\x00\x00...\x00\x00\x00\x00\x00\x00\x00}}
[o.e.jetty.server.HttpInput ] - HttpInputOverHTTP@3716942e[c=0,q=0,[0]=null,s=STREAM] addContent Content@2bcdd012{HeapByteBufferR@793bf03f[p=273,l=308,c=8192,r=35]={POST /aud... 35\r\n\r\n<<<{\n "eventTypeId": "USR-05 \\" "\n}>>>\x00\x00\x00\x00\x00\x00\x00\x00\x00...\x00\x00\x00\x00\x00\x00\x00}}
[o.e.jetty.http.HttpParser ] - CONTENT --> CONTENT_END
[o.e.jetty.server.HttpChannel ] - onContentComplete HttpChannelOverHttp@f084976{s=HttpChannelState@4962b62c{s=HANDLING rs=BLOCKING os=OPEN is=IDLE awp=false se=false i=true al=1},r=1,c=false/false,a=HANDLING,uri=//localhost:8686/audit/api/1/events/,age=36}
[o.e.jetty.http.HttpParser ] - CONTENT_END --> END
2. In Java Servlet Filter, if I extract the request payload from HttpServlet then I am getting below string as input:
{
"eventTypeId": "USR-05 " "
}
StackTrace:
[.JsonProcessingExceptionMapper] - Unable to process JSON ! com.fasterxml.jackson.databind.JsonMappingException: Unexpected character ('"' (code 34)): was expecting comma to separate Object entries
! at [Source: (org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream); line: *, column: ***] (through reference chain: com.anaplan.audit.write.api.request.AuditEventRequest["eventTypeId"])
! at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:402)
! at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:361)
! at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.wrapAndThrow(BeanDeserializerBase.java:1826)
! at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:280)
! at com.fasterxml.jackson.module.afterburner.deser.SuperSonicBeanDeserializer.deserialize(SuperSonicBeanDeserializer.java:155)
! Caused by: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('"' (code 34)): was expecting comma to separate Object entries
! at [Source: (org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream); line: 1, column: 395]
! at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:2418)
! at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:749)
! at com.fasterxml.jackson.core.base.ParserMinimalBase._reportUnexpectedChar(ParserMinimalBase.java:673)
! at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.nextFieldName(UTF8StreamJsonParser.java:1061)
! at com.fasterxml.jackson.databind.deser.std.MapDeserializer._readAndBindStringKeyMap(MapDeserializer.java:608)
More Details:
Kotlin Version: 1.3.0
JDK version: 1.8
jackson-module-kotlin: 2.8.9