use of com.google.gson.JsonPrimitive in project intellij-plugins by JetBrains.
the class ExtractMethodFeedback method toJson.
public JsonObject toJson() {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("offset", offset);
jsonObject.addProperty("length", length);
jsonObject.addProperty("returnType", returnType);
JsonArray jsonArrayNames = new JsonArray();
for (String elt : names) {
jsonArrayNames.add(new JsonPrimitive(elt));
}
jsonObject.add("names", jsonArrayNames);
jsonObject.addProperty("canCreateGetter", canCreateGetter);
JsonArray jsonArrayParameters = new JsonArray();
for (RefactoringMethodParameter elt : parameters) {
jsonArrayParameters.add(elt.toJson());
}
jsonObject.add("parameters", jsonArrayParameters);
JsonArray jsonArrayOffsets = new JsonArray();
for (int elt : offsets) {
jsonArrayOffsets.add(new JsonPrimitive(elt));
}
jsonObject.add("offsets", jsonArrayOffsets);
JsonArray jsonArrayLengths = new JsonArray();
for (int elt : lengths) {
jsonArrayLengths.add(new JsonPrimitive(elt));
}
jsonObject.add("lengths", jsonArrayLengths);
return jsonObject;
}
use of com.google.gson.JsonPrimitive in project intellij-plugins by JetBrains.
the class ContextData method toJson.
public JsonObject toJson() {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("name", name);
jsonObject.addProperty("explicitFileCount", explicitFileCount);
jsonObject.addProperty("implicitFileCount", implicitFileCount);
jsonObject.addProperty("workItemQueueLength", workItemQueueLength);
JsonArray jsonArrayCacheEntryExceptions = new JsonArray();
for (String elt : cacheEntryExceptions) {
jsonArrayCacheEntryExceptions.add(new JsonPrimitive(elt));
}
jsonObject.add("cacheEntryExceptions", jsonArrayCacheEntryExceptions);
return jsonObject;
}
use of com.google.gson.JsonPrimitive in project CodeUtils by boredream.
the class JsonUtils method getJsonPrimitiveType.
/**
* 将json元素中的json基础类型,转换为String.class,int.class等具体的类型
*
* @param je json元素
* @return 具体数据类型, 无法预估的类型统一视为Object.class类型
*/
private static Class<?> getJsonPrimitiveType(JsonElement je) {
Class<?> clazz = Object.class;
JsonPrimitive jp = je.getAsJsonPrimitive();
// json中的类型会将数字集合成一个总的number类型,需要分别判断
if (jp.isNumber()) {
String num = jp.getAsString();
if (num.contains(".")) {
// 如果包含"."则为小数,先尝试解析成float,如果失败则视为double
try {
Float.parseFloat(num);
clazz = float.class;
} catch (NumberFormatException e) {
clazz = double.class;
}
} else {
// 如果不包含"."则为整数,先尝试解析成int,如果失败则视为long
try {
Integer.parseInt(num);
clazz = int.class;
} catch (NumberFormatException e) {
clazz = long.class;
}
}
} else if (jp.isBoolean()) {
clazz = boolean.class;
} else if (jp.isString()) {
clazz = String.class;
}
// json中没有其他具体类型如byte等
return clazz;
}
use of com.google.gson.JsonPrimitive in project GeoGig by boundlessgeo.
the class HttpRemoteRepo method createFetchMessage.
private JsonObject createFetchMessage(List<ObjectId> want, Set<ObjectId> have) {
JsonObject message = new JsonObject();
JsonArray wantArray = new JsonArray();
for (ObjectId id : want) {
wantArray.add(new JsonPrimitive(id.toString()));
}
JsonArray haveArray = new JsonArray();
for (ObjectId id : have) {
haveArray.add(new JsonPrimitive(id.toString()));
}
message.add("want", wantArray);
message.add("have", haveArray);
return message;
}
use of com.google.gson.JsonPrimitive in project tika by apache.
the class JsonMetadataSerializer method serialize.
/**
* Serializes a Metadata object into effectively Map<String, String[]>.
*
* @param metadata object to serialize
* @param type (ignored)
* @param context (ignored)
* @return JsonElement with key/value(s) pairs or JsonNull if metadata is null.
*/
@Override
public JsonElement serialize(Metadata metadata, Type type, JsonSerializationContext context) {
if (metadata == null) {
return JsonNull.INSTANCE;
}
String[] names = getNames(metadata);
if (names == null) {
return JsonNull.INSTANCE;
}
JsonObject root = new JsonObject();
for (String n : names) {
String[] vals = metadata.getValues(n);
if (vals == null) {
//silently skip
continue;
}
if (vals.length == 1) {
root.addProperty(n, vals[0]);
} else {
JsonArray jArr = new JsonArray();
for (int i = 0; i < vals.length; i++) {
jArr.add(new JsonPrimitive(vals[i]));
}
root.add(n, jArr);
}
}
return root;
}
Aggregations