Author: aparfonov
Date: 2011-01-06 08:49:47 -0500 (Thu, 06 Jan 2011)
New Revision: 3781
Modified:
ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/provider/JsonEntityProvider.java
Log:
EXOJCR-1143
Modified:
ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/provider/JsonEntityProvider.java
===================================================================
---
ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/provider/JsonEntityProvider.java 2011-01-06
10:51:40 UTC (rev 3780)
+++
ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/provider/JsonEntityProvider.java 2011-01-06
13:49:47 UTC (rev 3781)
@@ -70,10 +70,9 @@
// and if this content type set trust it and try parse/write
/** Do not process via JSON "known" JAX-RS types and some more. */
- private static final Class<?>[] IGNORED =
- new Class<?>[]{byte[].class, char[].class, DataSource.class, DOMSource.class,
File.class, InputStream.class,
- OutputStream.class, JAXBElement.class, MultivaluedMap.class, Reader.class,
Writer.class, SAXSource.class,
- StreamingOutput.class, StreamSource.class, String.class};
+ private static final Class<?>[] IGNORED = new Class<?>[]{byte[].class,
char[].class, DataSource.class,
+ DOMSource.class, File.class, InputStream.class, OutputStream.class,
JAXBElement.class, MultivaluedMap.class,
+ Reader.class, Writer.class, SAXSource.class, StreamingOutput.class,
StreamSource.class, String.class};
private static boolean isIgnored(Class<?> type)
{
@@ -111,6 +110,12 @@
parser.parse(entityStream, handler);
JsonValue jsonValue = handler.getJsonObject();
+ if (JsonValue.class.isAssignableFrom(type))
+ {
+ // If requested object is JsonValue then stop processing here.
+ return jsonValue;
+ }
+
Types jtype = JsonUtils.getType(type);
if (jtype == Types.ARRAY_BOOLEAN || jtype == Types.ARRAY_BYTE || jtype ==
Types.ARRAY_SHORT
|| jtype == Types.ARRAY_INT || jtype == Types.ARRAY_LONG || jtype ==
Types.ARRAY_FLOAT
@@ -166,27 +171,34 @@
{
JsonGeneratorImpl generator = new JsonGeneratorImpl();
JsonValue jsonValue = null;
- Types jtype = JsonUtils.getType(type);
- if (jtype == Types.ARRAY_BOOLEAN || jtype == Types.ARRAY_BYTE || jtype ==
Types.ARRAY_SHORT
- || jtype == Types.ARRAY_INT || jtype == Types.ARRAY_LONG || jtype ==
Types.ARRAY_FLOAT
- || jtype == Types.ARRAY_DOUBLE || jtype == Types.ARRAY_CHAR || jtype ==
Types.ARRAY_STRING
- || jtype == Types.ARRAY_OBJECT)
+ if (t instanceof JsonValue)
{
- jsonValue = generator.createJsonArray(t);
+ // Don't do any transformation if object is prepared JsonValue.
+ jsonValue = (JsonValue)t;
}
- else if (jtype == Types.COLLECTION)
- {
- jsonValue = generator.createJsonArray((Collection<?>)t);
- }
- else if (jtype == Types.MAP)
- {
- jsonValue = generator.createJsonObjectFromMap((Map<String, ?>)t);
- }
else
{
- jsonValue = generator.createJsonObject(t);
+ Types jtype = JsonUtils.getType(type);
+ if (jtype == Types.ARRAY_BOOLEAN || jtype == Types.ARRAY_BYTE || jtype ==
Types.ARRAY_SHORT
+ || jtype == Types.ARRAY_INT || jtype == Types.ARRAY_LONG || jtype ==
Types.ARRAY_FLOAT
+ || jtype == Types.ARRAY_DOUBLE || jtype == Types.ARRAY_CHAR || jtype ==
Types.ARRAY_STRING
+ || jtype == Types.ARRAY_OBJECT)
+ {
+ jsonValue = generator.createJsonArray(t);
+ }
+ else if (jtype == Types.COLLECTION)
+ {
+ jsonValue = generator.createJsonArray((Collection<?>)t);
+ }
+ else if (jtype == Types.MAP)
+ {
+ jsonValue = generator.createJsonObjectFromMap((Map<String, ?>)t);
+ }
+ else
+ {
+ jsonValue = generator.createJsonObject(t);
+ }
}
-
JsonWriterImpl jsonWriter = new JsonWriterImpl(entityStream);
jsonValue.writeTo(jsonWriter);
jsonWriter.flush();
Show replies by date