Class JsonEncoder
- java.lang.Object
-
- com.supermap.services.rest.encoders.Encoder
-
- com.supermap.services.rest.encoders.JsonEncoder
-
- All Implemented Interfaces:
- javax.ws.rs.ext.MessageBodyWriter
- Direct Known Subclasses:
- GeoJSONEncoder, JsonpEncoder, RJsonEncoder
@Provider public class JsonEncoder extends Encoder implements javax.ws.rs.ext.MessageBodyWriter
${services_rest_encoders_JsonEncoder_Title}
${services_rest_encoders_JsonEncoder_Description}
-
-
Constructor Summary
Constructors Constructor and Description JsonEncoder()${services_rest_encoders_JsonEncoder_constructor_JsonEncoder_Title}
-
Method Summary
Methods Modifier and Type Method and Description protected java.util.List<MediaType>createSupportedMediaTypes()${services_rest_encoders_JsonEncoder_method_createSupportedMediaTypes_Title}longgetSize(java.lang.Object o, java.lang.Class type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations, javax.ws.rs.core.MediaType mediaType)Determines the length of the object to be written after serialization.protected booleanisindent()Whether to generate a string in an indented format.booleanisWriteable(java.lang.Class type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations, javax.ws.rs.core.MediaType mediaType)Determines whether the present expression supports the representation of the specified media type.protected java.lang.ObjecttoFormatedObject(java.lang.Object obj)Converts an object to an object of type JSONObject.protected java.lang.StringtoFormatedString(java.lang.Object resultObj)Will be standard objects such as: JSONObject, JSONArray converted to meet certain specifications of the string, such as JSON, JSONP and so on.RepresentationtoRepresentation(MediaType mediaType, java.lang.Object resourceObj)${services_rest_encoders_JsonEncoder_method_toRepresentation_Title}voidwriteTo(java.lang.Object o, java.lang.Class type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations, javax.ws.rs.core.MediaType mediaType, javax.ws.rs.core.MultivaluedMap httpHeaders, java.io.OutputStream entityStream)Generates an HTTP response for the specified media type.-
Methods inherited from class com.supermap.services.rest.encoders.Encoder
getSupportedMediaTypes, isEncodeAllow
-
-
-
-
Constructor Detail
-
JsonEncoder
public JsonEncoder()
${services_rest_encoders_JsonEncoder_constructor_JsonEncoder_Title}
${services_rest_encoders_JsonEncoder_constructor_JsonEncoder_Description}
-
-
Method Detail
-
isWriteable
public boolean isWriteable(java.lang.Class type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations, javax.ws.rs.core.MediaType mediaType)Determines whether the present expression supports the representation of the specified media type.
- Specified by:
isWriteablein interfacejavax.ws.rs.ext.MessageBodyWriter- Parameters:
type- The type of object to generate the expression.genericType- the specified object type.annotations- annotation array, the resource has these annotation methods to return to the object to be written.mediaType- The media type of the expected response.- Returns:
- Returns true if this expression generator supports the specified media type, false otherwise.
-
getSize
public long getSize(java.lang.Object o, java.lang.Class type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations, javax.ws.rs.core.MediaType mediaType)Determines the length of the object to be written after serialization. Is called before the HTTP response is generated.
- Specified by:
getSizein interfacejavax.ws.rs.ext.MessageBodyWriter- Parameters:
o- To generate an expression object.type- The Java class that corresponds to the object to be generated.genericType- To generate an expression object type.annotations- annotation array, the resource has these annotation methods to return to the object to be written.mediaType- The media type of the HTTP response.- Returns:
- the length of the object to be written.
-
writeTo
public void writeTo(java.lang.Object o, java.lang.Class type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations, javax.ws.rs.core.MediaType mediaType, javax.ws.rs.core.MultivaluedMap httpHeaders, java.io.OutputStream entityStream) throws java.io.IOException, javax.ws.rs.WebApplicationExceptionGenerates an HTTP response for the specified media type.
- Specified by:
writeToin interfacejavax.ws.rs.ext.MessageBodyWriter- Parameters:
o- To generate an expression object.type- The Java class that corresponds to the object to be generated.genericType- To generate an expression object type.annotations- annotation array, the resource has these annotation methods to return to the object to be written.mediaType- HTTP The media type of the response.httpHeaders- HTTP Response to the message header.entityStream- HTTP response.- Throws:
java.io.IOException- When the read and write process is wrong.javax.ws.rs.WebApplicationException- When the HTTP response fails.
-
createSupportedMediaTypes
protected java.util.List<MediaType> createSupportedMediaTypes()
${services_rest_encoders_JsonEncoder_method_createSupportedMediaTypes_Title}
${services_rest_encoders_JsonEncoder_method_createSupportedMediaTypes_Description}
- Specified by:
createSupportedMediaTypesin classEncoder- Returns:
- ${services_rest_encoders_JsonEncoder_method_createSupportedMediaTypes_return}
-
toRepresentation
public Representation toRepresentation(MediaType mediaType, java.lang.Object resourceObj)${services_rest_encoders_JsonEncoder_method_toRepresentation_Title}
${services_rest_encoders_JsonEncoder_method_toRepresentation_Description}
- Specified by:
toRepresentationin classEncoder- Parameters:
mediaType- ${services_rest_encoders_JsonEncoder_method_toRepresentation_param_mediaType}resourceObj- ${services_rest_encoders_JsonEncoder_method_toRepresentation_param_resourceObj}- Returns:
- ${services_rest_encoders_JsonEncoder_method_toRepresentation_return}
-
toFormatedObject
protected java.lang.Object toFormatedObject(java.lang.Object obj)
Converts an object to an object of type JSONObject. If the incoming parameter is of the base type, it is not converted and returns null.
- Parameters:
obj- The Java object to be converted.- Returns:
- converted JSONObject object.
-
toFormatedString
protected java.lang.String toFormatedString(java.lang.Object resultObj)
Will be standard objects such as: JSONObject, JSONArray converted to meet certain specifications of the string, such as JSON, JSONP and so on.
- Parameters:
resultObj- The object to be converted.- Returns:
- Result string.
-
isindent
protected boolean isindent()
Whether to generate a string in an indented format.
- Returns:
- Returns true if the string is generated in an indented format, false otherwise.
-
-