Class MessageTypeAdapter
- java.lang.Object
-
- com.google.gson.TypeAdapter<Message>
-
- org.eclipse.lsp4j.jsonrpc.json.adapters.MessageTypeAdapter
-
public class MessageTypeAdapter extends com.google.gson.TypeAdapter<Message>
The type adapter for messages dispatches between the different message types:RequestMessage,ResponseMessage, andNotificationMessage.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMessageTypeAdapter.Factory
-
Constructor Summary
Constructors Constructor Description MessageTypeAdapter(MessageJsonHandler handler, com.google.gson.Gson gson)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected MessagecreateMessage(java.lang.String jsonrpc, Either<java.lang.String,java.lang.Number> id, java.lang.String method, java.lang.Object params, java.lang.Object responseResult, ResponseError responseError)protected java.lang.ObjectfromJson(com.google.gson.JsonElement element, java.lang.reflect.Type type)protected java.lang.ObjectfromJson(com.google.gson.stream.JsonReader in, java.lang.reflect.Type type)protected java.lang.reflect.Type[]getParameterTypes(java.lang.String method)protected voidhandleParameter(com.google.gson.stream.JsonWriter out, java.lang.Object params, java.lang.String method)protected booleanisNull(java.lang.Object value)protected booleanisNullOrVoidType(java.lang.reflect.Type type)protected java.lang.ObjectparseParams(com.google.gson.stream.JsonReader in, java.lang.String method)Convert the json input into the parameters object corresponding to the call made by method.protected java.lang.ObjectparseParams(java.lang.Object params, java.lang.String method)Convert the JsonElement into the parameters object corresponding to the call made by method.protected java.lang.ObjectparseResult(com.google.gson.stream.JsonReader in, java.lang.String id)Convert the json input into the result object corresponding to the call made by id.protected java.lang.ObjectparseResult(java.lang.Object result, java.lang.String id)Convert the JsonElement into the result object corresponding to the call made by id.Messageread(com.google.gson.stream.JsonReader in)voidwrite(com.google.gson.stream.JsonWriter out, Message message)protected voidwriteId(com.google.gson.stream.JsonWriter out, Either<java.lang.String,java.lang.Number> id)protected voidwriteNullValue(com.google.gson.stream.JsonWriter out)Use this method to write anullvalue even if the JSON writer is set to not serializenull.
-
-
-
Constructor Detail
-
MessageTypeAdapter
public MessageTypeAdapter(MessageJsonHandler handler, com.google.gson.Gson gson)
-
-
Method Detail
-
read
public Message read(com.google.gson.stream.JsonReader in) throws java.io.IOException, com.google.gson.JsonIOException, com.google.gson.JsonSyntaxException
- Specified by:
readin classcom.google.gson.TypeAdapter<Message>- Throws:
java.io.IOExceptioncom.google.gson.JsonIOExceptioncom.google.gson.JsonSyntaxException
-
parseResult
protected java.lang.Object parseResult(com.google.gson.stream.JsonReader in, java.lang.String id) throws com.google.gson.JsonIOException, com.google.gson.JsonSyntaxExceptionConvert the json input into the result object corresponding to the call made by id. If the id is not known until after parsing, callparseResult(Object, String)on the return value of this call for a second chance conversion.- Parameters:
in- json input to read fromid- id of request message this is in response to- Returns:
- correctly typed object if the correct expected type can be determined, or a JsonElement representing the result
- Throws:
com.google.gson.JsonIOExceptioncom.google.gson.JsonSyntaxException
-
parseResult
protected java.lang.Object parseResult(java.lang.Object result, java.lang.String id) throws com.google.gson.JsonSyntaxExceptionConvert the JsonElement into the result object corresponding to the call made by id. If the result is already converted, does nothing.- Parameters:
result- json element to read fromid- id of request message this is in response to- Returns:
- correctly typed object if the correct expected type can be determined, or result unmodified if no conversion can be done.
- Throws:
com.google.gson.JsonSyntaxException
-
parseParams
protected java.lang.Object parseParams(com.google.gson.stream.JsonReader in, java.lang.String method) throws java.io.IOException, com.google.gson.JsonIOExceptionConvert the json input into the parameters object corresponding to the call made by method. If the method is not known until after parsing, callparseParams(Object, String)on the return value of this call for a second chance conversion.- Parameters:
in- json input to read frommethod- method name of request- Returns:
- correctly typed object if the correct expected type can be determined, or a JsonElement representing the parameters
- Throws:
java.io.IOExceptioncom.google.gson.JsonIOException
-
parseParams
protected java.lang.Object parseParams(java.lang.Object params, java.lang.String method)Convert the JsonElement into the parameters object corresponding to the call made by method. If the result is already converted, does nothing.- Parameters:
params- json element to read frommethod- method name of request- Returns:
- correctly typed object if the correct expected type can be determined, or params unmodified if no conversion can be done.
-
fromJson
protected java.lang.Object fromJson(com.google.gson.stream.JsonReader in, java.lang.reflect.Type type) throws com.google.gson.JsonIOException- Throws:
com.google.gson.JsonIOException
-
fromJson
protected java.lang.Object fromJson(com.google.gson.JsonElement element, java.lang.reflect.Type type)
-
isNull
protected boolean isNull(java.lang.Object value)
-
isNullOrVoidType
protected boolean isNullOrVoidType(java.lang.reflect.Type type)
-
getParameterTypes
protected java.lang.reflect.Type[] getParameterTypes(java.lang.String method)
-
createMessage
protected Message createMessage(java.lang.String jsonrpc, Either<java.lang.String,java.lang.Number> id, java.lang.String method, java.lang.Object params, java.lang.Object responseResult, ResponseError responseError) throws com.google.gson.JsonParseException
- Throws:
com.google.gson.JsonParseException
-
write
public void write(com.google.gson.stream.JsonWriter out, Message message) throws java.io.IOException- Specified by:
writein classcom.google.gson.TypeAdapter<Message>- Throws:
java.io.IOException
-
handleParameter
protected void handleParameter(com.google.gson.stream.JsonWriter out, java.lang.Object params, java.lang.String method)
-
writeId
protected void writeId(com.google.gson.stream.JsonWriter out, Either<java.lang.String,java.lang.Number> id) throws java.io.IOException- Throws:
java.io.IOException
-
writeNullValue
protected void writeNullValue(com.google.gson.stream.JsonWriter out) throws java.io.IOExceptionUse this method to write anullvalue even if the JSON writer is set to not serializenull.- Throws:
java.io.IOException
-
-