0

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!

Community
  • 1
  • 1
ecbrodie
  • 9,397
  • 19
  • 62
  • 109
  • Err...crap sorry, disregard the first question if you wish. I should've read [this Sitebricks.org page](http://sitebricks.org/#requestandreply) more carefully. *"Json.class - Jackson based Json transport"*. Second question is still up for grabs. – ecbrodie Nov 09 '12 at 05:10

2 Answers2

1

Sitebricks uses Jackson by default which will convert objects without any configuration using sensible defaults. If you want to override the behavior, bind an ObjectMapper using standard Jackson-prescribed config.

You should probably set application/json for most cases, correct. SB should set this, you're right, I'll make the change in trunk.

1

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");
Thomas
  • 1,400
  • 9
  • 24