com.supermap.services.rest.encoders
类 JsonEncoder
- java.lang.Object
-
- com.supermap.services.rest.encoders.Encoder
-
- com.supermap.services.rest.encoders.JsonEncoder
-
- 所有已实现的接口:
- javax.ws.rs.ext.MessageBodyWriter
- 直接已知子类:
- GeoJSONEncoder, JsonpEncoder, RJsonEncoder
@Provider public class JsonEncoder extends Encoder implements javax.ws.rs.ext.MessageBodyWriter
Java 对象的 JSON 序列化器。
负责将一个 Java 对象序列化成一个 JSON 字符串。
-
-
构造器概要
构造器 构造器和说明 JsonEncoder()构造函数。
-
方法概要
方法 限定符和类型 方法和说明 protected java.util.List<MediaType>createSupportedMediaTypes()创建支持的媒体类型,这里是 JSON 类型。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)确定要写入的对象序列化之后的长度。protected booleanisindent()是否按缩进的格式来产生字符串。booleanisWriteable(java.lang.Class type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations, javax.ws.rs.core.MediaType mediaType)判断本表述生成器是否支持指定媒体类型的表述。protected java.lang.ObjecttoFormatedObject(java.lang.Object obj)将一个对象转换成 JSONObject 类型的对象。protected java.lang.StringtoFormatedString(java.lang.Object resultObj)将规范对象如:JSONObject、JSONArray 转换成符合一定规范的字符串,如 JSON、JSONP 等。RepresentationtoRepresentation(MediaType mediaType, java.lang.Object resourceObj)将一个 Java 对象序列化为表述。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)生成指定媒体类型的 HTTP 响应。-
从类继承的方法 com.supermap.services.rest.encoders.Encoder
getSupportedMediaTypes, isEncodeAllow
-
-
-
-
方法详细资料
-
isWriteable
public boolean isWriteable(java.lang.Class type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations, javax.ws.rs.core.MediaType mediaType)判断本表述生成器是否支持指定媒体类型的表述。
- 指定者:
isWriteable在接口中javax.ws.rs.ext.MessageBodyWriter- 参数:
type- 要生成表述的对象类型。genericType- 指定的对象类型。annotations- 注记数组,资源中有这些注记的方法返回要写入的对象。mediaType- 预期响应的媒体类型。- 返回:
- 如果本表述生成器支持指定的媒体类型,则返回 true,否则返回 false。
-
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)确定要写入的对象序列化之后的长度。在生成 HTTP 响应之前被调用。
- 指定者:
getSize在接口中javax.ws.rs.ext.MessageBodyWriter- 参数:
o- 要生成表述的对象。type- 要生成表述的对象对应的 Java 类。genericType- 要生成表述的对象的类型。annotations- 注记数组,资源中有这些注记的方法返回要写入的对象。mediaType- HTTP 请求体的媒体类型。- 返回:
- 要写入的对象的长度。
-
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.WebApplicationException生成指定媒体类型的 HTTP 响应。
- 指定者:
writeTo在接口中javax.ws.rs.ext.MessageBodyWriter- 参数:
o- 要生成表述的对象。type- 要生成表述的对象对应的 Java 类。genericType- 要生成表述的对象的类型。annotations- 注记数组,资源中有这些注记的方法返回要写入的对象。mediaType- HTTP 响应的媒体类型。httpHeaders- HTTP 响应的消息头。entityStream- HTTP 响应。- 抛出:
java.io.IOException- 当读写过程出错时。javax.ws.rs.WebApplicationException- 当 HTTP 响应出错时。
-
createSupportedMediaTypes
protected java.util.List<MediaType> createSupportedMediaTypes()
创建支持的媒体类型,这里是 JSON 类型。
用户扩展一个 Encoder 时,需要指定该 Encoder 支持将格式化的对象转换为什么媒体类型的表述。
- 指定者:
createSupportedMediaTypes在类中Encoder- 返回:
- 媒体类型列表。
-
toRepresentation
public Representation toRepresentation(MediaType mediaType, java.lang.Object resourceObj)将一个 Java 对象序列化为表述。
- 指定者:
toRepresentation在类中Encoder- 参数:
mediaType- 表述的类型。resourceObj- 欲序列化为表述的 Java 对象。- 返回:
- resourceObj 对象的 JSON 格式表述。
-
toFormatedObject
protected java.lang.Object toFormatedObject(java.lang.Object obj)
将一个对象转换成 JSONObject 类型的对象。如果传入的参数是基本类型则不予转换,返回null 。
- 参数:
obj- 要转换的 Java 对象。- 返回:
- 转换后的 JSONObject 对象。
-
toFormatedString
protected java.lang.String toFormatedString(java.lang.Object resultObj)
将规范对象如:JSONObject、JSONArray 转换成符合一定规范的字符串,如 JSON、JSONP 等。
- 参数:
resultObj- 要转换的对象。- 返回:
- 结果字符串。
-
isindent
protected boolean isindent()
是否按缩进的格式来产生字符串。
- 返回:
- 如果按缩进的格式来产生字符串则返回 true,否则返回 false。
-
-