package org.jboss.aerogear.unifiedpush.cassandra.dao.model.parser;

import org.jboss.aerogear.unifiedpush.cassandra.dao.impl.DocumentKey;
import org.jboss.aerogear.unifiedpush.cassandra.dao.model.DocumentContent;

import com.fasterxml.jackson.annotation.JsonRawValue;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

/**
 * JSON wrapper parser to DocumentContent. JSON is serialized by including
 * literal String content as is, without quoting of characters.
 * <p>
 * Warning: the resulting JSON stream may be invalid depending on your input
 * value.
 */
public class JsonDocumentContent extends DocumentContent {
	private static final String CONTENT_TYPE = "application/json";

	public JsonDocumentContent() {
		super();
		super.setContentType(CONTENT_TYPE);
	}

	public JsonDocumentContent(DocumentKey key, String content, String documentId) {
		super(key, content, documentId);
	}

	public JsonDocumentContent(DocumentKey key, String content) {
		super(key, content);
	}

	@JsonRawValue
	@Override
	public String getContent() {
		return super.getContent();
	}

	@JsonDeserialize(using = JsonRawValueDeserializer.class)
	@Override
	public void setContent(String content) {
		super.setContent(content.toString());
	}

	@Override
	public void setContentType(String contentType) {
		if (!CONTENT_TYPE.equals(contentType)) {
			throw new UnsupportedContentTypeException(String.format("Only %s type is permitted.", CONTENT_TYPE));
		}
		super.setContentType(contentType);
	}
}

@@ -61,16 +61,40 @@
 arser;%0A%0A
+import java.util.UUID;%0A%0A
 import o
@@ -231,16 +231,132 @@
 ntent;%0A%0A
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;%0Aimport com.fasterxml.jackson.annotation.JsonProperty;%0A
 import c
@@ -618,16 +618,145 @@
 %0A * %3Cp%3E%0A
+ * Clients (JAVA) might serialize using %7B@link IDocument%7D derived classes,%0A * therefore @JsonIgnoreProperties is enabled.%0A * %3Cp%3E%0A
  * Warni
@@ -838,16 +838,60 @@
 ue.%0A */%0A
+@JsonIgnoreProperties(ignoreUnknown = true)%0A
 public c
@@ -1798,11 +1798,116 @@
 ype);%0A%09%7D
+%0A%0A%09@JsonProperty(required = false)%0A%09public UUID getSnapshot() %7B%0A%09%09return super.getKey().getSnapshot();%0A%09%7D
 %0A%7D%0A

Parse document snapshot as UUID