Questions tagged [jackson-module-scala]

18 questions
10
votes
1 answer

jackson why do I need JsonTypeName annotation on subclasses

At this link I'm trying to understand why do I (may) need @JsonTypeName on subclasses (like all 'internet; sujests to put) if it works without it ? @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "aType") @JsonSubTypes(Array( new Type(value =…
ses
  • 13,174
  • 31
  • 123
  • 226
5
votes
2 answers

Did I just break JVM type safety by using Jackson JSON deserialisation?

This is what I got: import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.module.scala.DefaultScalaModuleobject AppStart extends App { val mapper = new ObjectMapper() mapper.registerModule(DefaultScalaModule) val…
brunedito
  • 53
  • 3
5
votes
0 answers

deserializing mongo document's DateField into java.util.Date

I'm using mongo-scala combination in one of my new projects and it requires deserializing a mongo document with date field mongo document example { "_id" : ObjectId("56603577616e082f559da3d9"), "type" : "rule", "startTime" :…
Rohit
  • 1,878
  • 19
  • 26
2
votes
1 answer

Scala Enum Serialization Fails using Jackson when DefaultTyping is enabled

I see that the Jackson library is failing to serialize Scala enums, when the DefaultTyping is enabled with OBJECT_AND_NON_CONCRETE setting. Please note that the serialization works fine when I use JAVA_LANG_OBJECT setting. I am seeing the below…
Varun
  • 73
  • 8
2
votes
1 answer

Scala: How to prevent Jackson from deserialization with null

Say I have a case case such as: case class Stuff(name:String,stuffs:List[String] = List.empty) How can I prevent jackson from deserialization the json { "name":"Alex" } With Stuff("Alex",null) I would prefer it to be constructed with…
aclowkay
  • 3,577
  • 5
  • 35
  • 66
2
votes
2 answers

Using Scala Jackson for JSON deserialization?

I am new to scala and trying to map my json to an object. I have found jackson-scala-module but unable to figure out how to use it. A small example might be of help. val json = { "_id" : "jzcyluvhqilqrocq" , "DP-Name" : "Sumit Agarwal" , "DP-Age" :…
Sumit Agarwal
  • 4,091
  • 8
  • 33
  • 49
2
votes
1 answer

Jackson / Scala immutable case classes: parsing a class depending on other value in JSON

I have a JSON like this: { "switch": "foo", "items": [ {"type": "one"}, {"type": "two"} ] } I want to load it into a structure of classes like that: case class MyFile( @JsonProperty("switch") _switch: String, …
GreyCat
  • 16,622
  • 18
  • 74
  • 112
1
vote
1 answer

Scala classOf generic type in Kafka json deserializer

I'm writing a kafka json deserializer in scala using Jackson but am having a problem providing jackson's readValue() method the class of a generic type. For example: ... import org.apache.kafka.common.serialization.Deserializer class…
novon
  • 973
  • 3
  • 15
  • 30
1
vote
0 answers

Deserializing generic list of objects to the right type with Jackson

My json string has an array at the top level. E.g.: [ {...}, {...} ] And I'm using jackson to deserialize it like so: val parser = mapper.getFactory.createParser(json) val mylist = mapper.readValue(parser, classOf[List[Track]]) The trouble is…
Filipe Correia
  • 5,415
  • 6
  • 32
  • 47
0
votes
0 answers

Exception: Scala module 2.14.1 requires Jackson Databind version >= 2.14.0 and < 2.15.0 - Found jackson-databind version 2.13.2-1

I am getting the exception " Scala module 2.14.1 requires Jackson Databind version >= 2.14.0 and < 2.15.0 - Found jackson-databind version 2.13.2-1" even though I have upgraded the Jackson Databind version tp 2.14.1 in the build.gardle file? How to…
0
votes
1 answer

Jackson annotation mixin on some of the fields doesn't work

Preface I'd like to deserialize json to the following class case class Target( a: Option[Long], b: String ) with the following code: val mapper = new ObjectMapper() .registerModule(DefaultScalaModule) val req = """{ | "a":…
lev
  • 3,986
  • 4
  • 33
  • 46
0
votes
1 answer

Stop jackson-scala-module serializing all fields by default

Using DefaultObjectMapper from jackson-scala-module, in the following examples, field is serialised in the Scala version, but not in the Java version. Setting com.fasterxml.jackson.databind.MapperFeature.AUTO_DETECT_FIELDS has no effect. I wish for…
oal
  • 411
  • 5
  • 15
0
votes
2 answers

Jackson: (de)serialising Map with arbitrary non-string key

I have a Scala Map keyed by a type that itself needs serialising to JSON. Because of the nature of JSON that requires key names for objects to be strings, a simple mapping is not directly possible. The work around I wish to implement is to convert…
oal
  • 411
  • 5
  • 15
0
votes
0 answers

Deserialize map of Int to Tuple using Jackson

I have a class that looks something like case class A (id: Int, name: String, marks: Map[Int, List(Long, Long)]) I am using Jackson to serialize and store the objects in a database and read them back. However, when I deserialize it the Map is…
0
votes
0 answers

Option type information lost when deserializing JSON into Map[String, Option[String]]

val mapper = new ObjectMapper mapper.registerModule(DefaultScalaModule) val original: Map[String, Option[String]] = Map[String, Option[String]]("key" -> Some("value")) val json: ObjectNode = new ObjectNode(JsonNodeFactory.instance).put("key",…
Grega Kešpret
  • 11,827
  • 6
  • 39
  • 44
1
2