0
votes

Using Jerkson version:

<dependency>
    <groupId>com.cloudphysics</groupId>
    <artifactId>jerkson_2.10</artifactId>
    <version>0.6.3</version>
</dependency>

I have this case class:

case class Parameter(val name:String, val value:String, @(JsonProperty@field)("type") val aType:String, val restriction:String, val defaultValue:String, val required:Boolean, val description:String)

The Json ouptut contains a field named 'type'. Obviusly this is a problem in Scala as 'type' is a key word. Although it looks like JsonProperty sold be supported this seems to be broken.

In a test I have this code:

val p = Parameter("name", "value", "string", "restricted", "myDefault", true, "desc")
println(Json.generate(p))

It prints:

{"name":"name","value":"value","aType":"string","restriction":"restricted","defaultValue":"myDefault","required":true,"description":"desc"}

'aType' and not 'type'

Any ideas what am I doing wrong?

1

1 Answers

1
votes

Scala will allow you to use keywords (and everything) to name things if you put them in ticks (`)

case class Parameter( ..., `type`: String,  ....)

this will give you what you want.


Jerkson project is abandoned.

If this were jackson with scala module your code would be fine, @JsonProperty("type") would also do the job.