use of com.google.gson.GsonBuilder in project immutables by immutables.
the class Ent method main.
public static void main(String... args) throws UnknownHostException {
MongoClient client = new MongoClient("localhost");
RepositorySetup setup = RepositorySetup.builder().database(client.getDB("test")).executor(MoreExecutors.listeningDecorator(Executors.newCachedThreadPool())).gson(new GsonBuilder().registerTypeAdapterFactory(new GsonAdaptersEnt()).create()).build();
EntRepository repository = new EntRepository(setup);
EntRepository.Criteria where = repository.criteria().uuid("8b7a881c-6ccb-4ada-8f6a-60cc99e6aa20").actionIn("BAN", "IPBAN");
Criteria or = where.expiresAbsent().or().with(where).expiresGreaterThan(TimeInstant.of(1467364749679L));
System.out.println(or);
repository.find(or).fetchAll().getUnchecked();
}
use of com.google.gson.GsonBuilder in project scss-lint-plugin by idok.
the class Lint method parse.
// public File file;
//
// public static Lint read(String xml) {
// XStream xstream = new XStream();
// xstream.alias("lint", Lint.class);
// xstream.alias("file", File.class);
// xstream.alias("issue", Issue.class);
// xstream.addImplicitCollection(File.class, "issues");
// xstream.useAttributeFor(File.class, "name");
// xstream.useAttributeFor(Issue.class, "linter");
// xstream.useAttributeFor(Issue.class, "line");
// xstream.useAttributeFor(Issue.class, "column");
// xstream.useAttributeFor(Issue.class, "length");
// xstream.useAttributeFor(Issue.class, "severity");
// xstream.useAttributeFor(Issue.class, "reason");
// return (Lint) xstream.fromXML(xml);
// }
//
// public static class File {
// public String name;
// public List<Issue> issues = new ArrayList<Issue>();
// }
public static Map<String, List<Issue>> parse(String json) {
GsonBuilder builder = new GsonBuilder();
// builder.registerTypeAdapterFactory(adapter);
Gson g = builder.setPrettyPrinting().create();
Type listType = new TypeToken<Map<String, List<Issue>>>() {
}.getType();
return g.fromJson(json, listType);
}
use of com.google.gson.GsonBuilder in project jphp by jphp-compiler.
the class JsonExtension method createGsonBuilderForDecode.
public static GsonBuilder createGsonBuilderForDecode(MemoryDeserializer memoryDeserializer) {
GsonBuilder builder = new GsonBuilder();
builder.registerTypeAdapter(Memory.class, memoryDeserializer);
return builder;
}
use of com.google.gson.GsonBuilder in project jphp by jphp-compiler.
the class JsonExtension method createGsonBuilder.
public static GsonBuilder createGsonBuilder(MemorySerializer memorySerializer) {
GsonBuilder builder = new GsonBuilder();
builder.registerTypeAdapter(Memory.class, memorySerializer);
builder.registerTypeAdapter(NullMemory.class, memorySerializer);
builder.registerTypeAdapter(UndefinedMemory.class, memorySerializer);
builder.registerTypeAdapter(ReferenceMemory.class, memorySerializer);
builder.registerTypeAdapter(TrueMemory.class, memorySerializer);
builder.registerTypeAdapter(FalseMemory.class, memorySerializer);
builder.registerTypeAdapter(LongMemory.class, memorySerializer);
builder.registerTypeAdapter(DoubleMemory.class, memorySerializer);
builder.registerTypeAdapter(ObjectMemory.class, memorySerializer);
builder.registerTypeAdapter(ArrayMemory.class, memorySerializer);
builder.registerTypeAdapter(BinaryMemory.class, memorySerializer);
builder.registerTypeAdapter(CharMemory.class, memorySerializer);
builder.registerTypeAdapter(KeyValueMemory.class, memorySerializer);
builder.registerTypeAdapter(StringBuilderMemory.class, memorySerializer);
builder.registerTypeAdapter(StringMemory.class, memorySerializer);
return builder;
}
use of com.google.gson.GsonBuilder in project jphp by jphp-compiler.
the class JsonFunctions method json_decode.
public static Memory json_decode(Environment env, String json, boolean assoc, int depth) {
MemoryDeserializer memoryDeserializer = new MemoryDeserializer();
memoryDeserializer.setEnv(env);
GsonBuilder gsonBuilder = JsonExtension.createGsonBuilderForDecode(memoryDeserializer);
memoryDeserializer.setAssoc(assoc);
memoryDeserializer.setMaxDepth(depth);
Gson gson = gsonBuilder.create();
try {
env.setUserValue(JsonFunctions.class.getName() + "#error", null);
Memory r = gson.fromJson(json, Memory.class);
if (r == null)
return Memory.NULL;
else
return assoc ? r.toImmutable() : r;
} catch (MemoryDeserializer.MaxDepthException e) {
env.setUserValue(JsonFunctions.class.getName() + "#error", JsonConstants.JSON_ERROR_DEPTH);
} catch (JsonSyntaxException e) {
env.setUserValue(JsonFunctions.class.getName() + "#error", JsonConstants.JSON_ERROR_SYNTAX);
} catch (JsonParseException e) {
env.setUserValue(JsonFunctions.class.getName() + "#error", JsonConstants.JSON_ERROR_STATE_MISMATCH);
}
return Memory.NULL;
}
Aggregations