mongodb java deserialize long using gson
<p>I can insert a POJO containing a <code>long</code> field correctly using gson to a mongodb server.</p>

<p>But when I am de-serializing it back to the pojo using Gson I get this error:</p>

<pre><code>javax.servlet.ServletException: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected a long but was BEGIN_OBJECT at line 1 column 171 path $.sentTime
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected a long but was BEGIN_OBJECT at line 1 column 171 path $.sentTime
java.lang.IllegalStateException: Expected a long but was BEGIN_OBJECT at line 1 column 171 path $.sentTime
</code></pre>

<p>My mongo db document looks like this:</p>

<pre><code>{
    "_id" : ObjectId("57ff7c30385bb63b1c185b8e"),
    "chatId" : "57f95e8e385bb61c5cf2cd18",
    "sender" : "57ec1aaa0ffe16123439d52b",
    "message" : "Hello Again",
    "sentTime" : NumberLong("1476361264229")
}
</code></pre>

<p>POJO:</p>

<pre><code>public class MessageSingle implements Message {

private ObjectId id;
private String chatId;
private String sender;
private String message;
private MessageType messageType;
private long sentTime;

@Override
public ObjectId getId() {
    return id;
}

@Override
public void setId(ObjectId id) {
    this.id = id;
}

@Override
public String getChatId() {
    return chatId;
}

@Override
public void setChatId(String chatId) {
    this.chatId = chatId;
}

@Override
public void setSender(String sender) {
    this.sender=sender;
}

@Override
public String getSender() {
    return sender;
}

@Override
public void setMessage(String message) {
    this.message=message;
}

@Override
public String getMessage() {
    return message;
}

@Override
public void setMessageType(MessageType messageType) {
    this.messageType=messageType;
}

@Override
public MessageType getMessageType() {
    return messageType;
}

@Override
public void setSentTime(long time) {
    this.sentTime=time;
}

@Override
public long getSentTime() {
    return sentTime;
}
}
</code></pre>

<p>When I change the long to int or string it works well but not with long.
How do I solve the same.
Thanks</p>