com.android.ide.common.blame
Class MessageJsonSerializer
java.lang.Object
com.google.gson.TypeAdapter<com.android.ide.common.blame.Message>
com.android.ide.common.blame.MessageJsonSerializer
public class MessageJsonSerializer
- extends com.google.gson.TypeAdapter<com.android.ide.common.blame.Message>
Class to handle json serialization and deserialization of messages.
Reads json objects of the form:
{
"kind":"ERROR",
"text":"errorText",
"original":"unparsed error text: Error in some intermediate file",
"sources": [{
"file":"/path/to/source.java",
"position":{
"startLine":1,
"startColumn":2,
"startOffset":3,
"endLine":4,
"endColumn":5,
"endOffset":6
}
}]
}
All fields, other than text, may be omitted. They have the following defaults:
Property | Default | Notes |
kind (ERROR, WARNING,
INFO, UNKNOWN) | UNKNOWN | |
text | Empty String | Should not be omitted. |
file (Absolute) | {} [unknown] | See SourceFileJsonTypeAdapter |
position | UNKNOWN | |
startLine,
startColumn,
startOffset | -1 [unknown] | 0-based |
endLine,
endColumn,
endOffset | startLine, startColumn,
startOffset |
Notes
- Offset need not be included, if needed by the consumer of the message it can
be derived from the file, line and column.
- If line is included and column is not the message will be considered to apply
to the whole line.
- A message can have multiple sources.
It also can read legacy serialized objects of the form:
{
"kind":"ERROR",
"text":"errorText",
"sourcePath": "/path/to/source.java",
"position":{
"startLine":1,
"startColumn":2,
"startOffset":3,
"endLine":4,
"endColumn":5,
"endOffset":6
}
}
These serializers are implemented using the lower-level TypeAdapter gson API which gives much
more control and allow changes to be made without breaking backward compatibility.
Method Summary |
com.android.ide.common.blame.Message |
read(com.google.gson.stream.JsonReader in)
|
static void |
registerTypeAdapters(com.google.gson.GsonBuilder builder)
|
void |
write(com.google.gson.stream.JsonWriter out,
com.android.ide.common.blame.Message message)
|
Methods inherited from class com.google.gson.TypeAdapter |
fromJson, fromJson, fromJsonTree, nullSafe, toJson, toJson, toJsonTree |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
MessageJsonSerializer
public MessageJsonSerializer()
write
public void write(com.google.gson.stream.JsonWriter out,
com.android.ide.common.blame.Message message)
throws java.io.IOException
- Specified by:
write
in class com.google.gson.TypeAdapter<com.android.ide.common.blame.Message>
- Throws:
java.io.IOException
read
public com.android.ide.common.blame.Message read(com.google.gson.stream.JsonReader in)
throws java.io.IOException
- Specified by:
read
in class com.google.gson.TypeAdapter<com.android.ide.common.blame.Message>
- Throws:
java.io.IOException
registerTypeAdapters
public static void registerTypeAdapters(com.google.gson.GsonBuilder builder)