private void write(RawJsonWriter writer, LazyJson value) { String json = value.getJson(); json = json.substring(1, json.length() - 1); RawJsonWriter customWriter = writer; customWriter.writeRawString(json); }
private <T> void setLazyJsonProperty(T object, Field field, Object value) throws IllegalAccessException { String json = (String) value; Type type = ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0]; field.set(object, LazyJson.$create(type, json)); }
public boolean isJsonArray() { if (!isParsed()) { return json.charAt(0) == '['; } if (type instanceof ParameterizedType) { return List.class.isAssignableFrom((Class<?>) ((ParameterizedType) type).getRawType()); } return List.class.isAssignableFrom((Class<?>) type); }
public void setLazyPojo(Pojo lazyPojo) { this.lazyPojo.set(lazyPojo); }
public Map<Long, Pojo> getLazyMapPojo() { return lazyMapPojo.get(); }
private Map<String, LazyJson<List<Pojo>>> createMapWithLazyList() { Map<String, LazyJson<List<Pojo>>> mapWithLazyList = new HashMap<>(); mapWithLazyList.put("xpto", LazyJson.create(Arrays.asList(new Pojo("otpx"), new Pojo("xpto")))); return mapWithLazyList; }
/** * Internal only method. */ public static LazyJson<?> $create(Type type, String json) { LazyJson<?> lazyJson = new LazyJson<>(); lazyJson.type = type; lazyJson.json = json; return lazyJson; }
public void setLazyMapPojo(Map<Long, Pojo> lazyMapPojo) { this.lazyMapPojo.set(lazyMapPojo); }
public Pojo getLazyPojo() { return lazyPojo.get(); }
@Test public void testSerialize() { Pojo pojo = new Pojo("xpto"); LazyJson<Pojo> lazyJson = LazyJson.create(pojo); assertEquals(JsonUtils.to(pojo), JsonUtils.to(lazyJson)); }
@Override protected void write(JsonWriter out, LazyJson value, TypeAdapter<JsonElement> elementAdapter, TypeAdapter<LazyJson> delegate) throws IOException { if (value == null || value.getJson() == null) { out.nullValue(); return; } String json = value.getJson(); // This is done to avoid json serialize/deserialize to JsonObject since we already have the json as a String. // Could not find any better GSON API. JsonWriter wont let me write strings without escaping then. CustomJsonWriter customWriter = (CustomJsonWriter) out; begin(customWriter, value); customWriter.write(json.substring(1, json.length() - 1)); // Remove { and } end(customWriter, value); }
private LazyJson<?> createObject(Type rootType, JsonElement json) { return LazyJson.$create(rootType, json.getAsJsonObject().toString()); }
public void setLazyListPojo(List<Pojo> lazyListPojo) { this.lazyListPojo.set(lazyListPojo); }
@Test public void testLaziness() { String json = "{\"lazyPojo\":{\"stringValue\":\"xpto\", \"longValue\":100}}"; BasicObject object = JsonUtils.from(yawp, json, BasicObject.class); assertFalse(object.getLazyPojoAsLazyJson().isParsed()); assertEquals("xpto", object.getLazyPojo().getStringValue()); assertTrue(object.getLazyPojoAsLazyJson().isParsed()); }
public Map<IdRef<BasicObject>, Pojo> getLazyIdRefMapPojo() { return lazyIdRefMapPojo.get(); }
@Override public void serialize(LazyJson value, ObjectWriter writer, Context ctx) throws Exception { if (value == null || value.getJson() == null) { writer.writeNull(); return; } begin(value, writer); write((RawJsonWriter) writer, value); end(value, writer); }
private <T> void setLazyJsonProperty(T object, Field field, Object value) throws IllegalAccessException { String json = ((Text) value).getValue(); Type type = ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0]; field.set(object, LazyJson.$create(type, json)); }