javajsonserializationcontent-typesitebricks

Sitebricks JSON default serializer. And why does it return text/json instead of application/json


Hmm...I intended on asking only one question. But I've instead decided to kill two birds with one stone.

First Question: What does Sitebricks use as the default serializer/deserializer between Java POJOs and JSON? For example, let's say that this is my POJO:

public class MyObject {
    private String key;
    private int value;
    public MyObject (String k, int v) {
        this.key = k;
        this.value = v;
    }
}

And this is an example of a method in my Sitebricks servlet:

@Get
public Reply<?> listPools() {
    return Reply.with(new MyObject("Foo", 6)).as(Json.class);
}

I did not annotate MyObject with any Jackson annotations, nor did I use GSON anywhere in my code. Yet, much to my surprise, I get back this as my content body in the response:

{"value":6,"key":"Foo"}

So what I would like to know is what technology or framework or what-not that Sitebricks is using by default to serialize-deserialize JSON. Jackson? GSON? Witchcraft and wizardry?

Now the Second Question. I noticed in the header that the response Content-Type was text/json. This looked weird to me because, in my past experience, I've always dealt with application/json as the Content-Type for JSON. This Stackoverflow post confirms my belief. Any comments on this point?

Thanks in advance!


Solution

  • And it's still possible to change it on the go with the following

     return Reply.with(...).as(Json.class).type("application/json; charset=utf-8");