本文整理汇总了Java中com.bluelinelabs.logansquare.LoganSquare.serialize方法的典型用法代码示例。如果您正苦于以下问题:Java LoganSquare.serialize方法的具体用法?Java LoganSquare.serialize怎么用?Java LoganSquare.serialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.bluelinelabs.logansquare.LoganSquare
的用法示例。
在下文中一共展示了LoganSquare.serialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: nestedCollection
import com.bluelinelabs.logansquare.LoganSquare; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void nestedCollection() {
List<ArrayList<Set<Map<String, List<String>>>>>[] array = (List<ArrayList<Set<Map<String, List<String>>>>>[])new List<?>[] {getStringListMapSetArrayListList() };
NestedCollectionModel model = new NestedCollectionModel();
model.crazyCollection = array;
String json = null;
try {
json = LoganSquare.serialize(model);
} catch (Exception e) {
e.printStackTrace();
}
ASSERT.that(json).isNotNull();
NestedCollectionModel reconstructedModel = null;
try {
reconstructedModel = LoganSquare.parse(json, NestedCollectionModel.class);
} catch (Exception ignored) { }
// Comparing the json doesn't work so well on arrays, since they could be reordered. We'll compare the output instead.
ASSERT.that(model.equals(reconstructedModel)).isTrue();
}
示例2: toBody
import com.bluelinelabs.logansquare.LoganSquare; //导入方法依赖的package包/类
@SuppressWarnings("unchecked") @Override public TypedOutput toBody(Object object) {
try {
// Check if the type contains a parametrized list
if (List.class.isAssignableFrom(object.getClass())) {
// Convert the input to a list first, access the first element and serialize the list
List<Object> list = (List<Object>) object;
if (list.isEmpty()) {
return new TypedString("[]");
} else {
Object firstElement = list.get(0);
return new TypedString(LoganSquare.serialize(list, (Class<Object>) firstElement.getClass()));
}
} else {
// Serialize single elements immediately
return new TypedString(LoganSquare.serialize(object));
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例3: serialize
import com.bluelinelabs.logansquare.LoganSquare; //导入方法依赖的package包/类
@Nullable
public String serialize() {
if (notification == null) return null;
// TODO androidNotification
//androidNotification = new AndroidNotification();
//androidNotification.android.notification = notification;
//String text = androidNotification.serialize();
//LoganSquare.registerTypeConverter(Notification.class, new NotificationConverter(context));
LoganSquare.registerTypeConverter(PendingIntent.class, new PendingIntentConverter(context));
try {
return LoganSquare.serialize(NotificationConverter.toSimpleNotification(notification));
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
示例4: toBody
import com.bluelinelabs.logansquare.LoganSquare; //导入方法依赖的package包/类
@SuppressWarnings("unchecked") @Override public TypedOutput toBody(Object object) {
try {
// Check if the type contains a parametrized list
if (List.class.isAssignableFrom(object.getClass())) {
// Convert the input to a list first, access the first element and serialize the list
List<Object> list = (List<Object>) object;
if (list.isEmpty()) {
return new TypedString("[]");
} else {
Object firstElement = list.get(0);
return new TypedString(
LoganSquare.serialize(list, (Class<Object>) firstElement.getClass()));
}
} else {
// Serialize single elements immediately
return new TypedString(LoganSquare.serialize(object));
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例5: shouldBeSameObjectAfterJsonParsing
import com.bluelinelabs.logansquare.LoganSquare; //导入方法依赖的package包/类
@Test
public void shouldBeSameObjectAfterJsonParsing() throws IOException {
// given
SkuDetails originalSku = new SkuDetails();
originalSku.setCurrency("EUR");
originalSku.setDescription("description");
originalSku.setPriceText("priceText");
originalSku.setPriceValueMicros(BigDecimal.valueOf(1230000));
originalSku.setProductId("productId");
originalSku.setSubscription("sub");
originalSku.setTitle("title");
// when
String json = LoganSquare.serialize(originalSku);
SkuDetails outputSku = LoganSquare.parse(json, SkuDetails.class);
// then
assertThat(outputSku).isEqualTo(originalSku);
}
示例6: toBody
import com.bluelinelabs.logansquare.LoganSquare; //导入方法依赖的package包/类
@SuppressWarnings("unchecked") @Override public TypedOutput toBody(Object object) {
try {
// Check if the type contains a parametrized list
if (List.class.isAssignableFrom(object.getClass())) {
// Convert the input to a list first, access the first element and serialize the list
List<Object> list = (List<Object>) object;
if (list.isEmpty()) {
return new TypedString("[]");
} else {
Object firstElement = list.get(0);
return new TypedString(LoganSquare.serialize(list, (Class<Object>) firstElement.getClass()));
}
} else {
// Serialize single elements immediately
return new TypedString(LoganSquare.serialize(object));
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例7: toBody
import com.bluelinelabs.logansquare.LoganSquare; //导入方法依赖的package包/类
@Override
public TypedOutput toBody(Object object) {
try {
// Check if the type contains a parametrized list
if (List.class.isAssignableFrom(object.getClass())) {
// Convert the input to a list first, access the first element and serialize the list
List<Object> list = (List<Object>) object;
if (list.isEmpty()) {
return new TypedString("[]");
}
else {
Object firstElement = list.get(0);
return new TypedString(LoganSquare.serialize(list, (Class<Object>) firstElement.getClass()));
}
}
else {
// Serialize single elements immediately
return new TypedString(LoganSquare.serialize(object));
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例8: serialize
import com.bluelinelabs.logansquare.LoganSquare; //导入方法依赖的package包/类
@Override
protected String serialize(Response response) {
try {
return LoganSquare.serialize(response);
} catch (Exception e) {
return null;
} finally {
System.gc();
}
}
示例9: stringList
import com.bluelinelabs.logansquare.LoganSquare; //导入方法依赖的package包/类
@Test
public void stringList() {
String json = "[\"test1\",\"test2\",\"test3\",\"test4\"]";
String reserialized = null;
try {
List<String> list = LoganSquare.parseList(json, String.class);
reserialized = LoganSquare.serialize(list, String.class);
} catch (Exception ignored) { }
ASSERT.that(json.equals(reserialized)).isTrue();
}
示例10: intList
import com.bluelinelabs.logansquare.LoganSquare; //导入方法依赖的package包/类
@Test
public void intList() {
String json = "[1,2,3,4,5,6]";
String reserialized = null;
try {
List<Integer> list = LoganSquare.parseList(json, Integer.class);
reserialized = LoganSquare.serialize(list, Integer.class);
} catch (Exception ignored) { }
ASSERT.that(json.equals(reserialized)).isTrue();
}
示例11: simpleObjectMap
import com.bluelinelabs.logansquare.LoganSquare; //导入方法依赖的package包/类
@Test
public void simpleObjectMap() {
String json = "{\"obj1\":{\"date\":\"2015-02-21T18:45:50.748+0000\",\"string\":\"testString\",\"test_double\":342.0,\"test_double_obj\":345.0,\"test_float\":898.0,\"test_float_obj\":382.0,\"test_int\":32,\"test_int_obj\":323,\"test_long\":932,\"test_long_obj\":3920,\"test_string\":\"anotherTestString\"}," +
"\"obj2\":{\"date\":\"2015-02-22T18:45:50.748+0000\",\"string\":\"testString2\",\"test_double\":342.0,\"test_double_obj\":345.0,\"test_float\":898.0,\"test_float_obj\":382.0,\"test_int\":32,\"test_int_obj\":323,\"test_long\":932,\"test_long_obj\":3920,\"test_string\":\"anotherTestString\"}}";
String reserialized = null;
try {
Map<String, SimpleModel> simpleModelMap = new TreeMap<>(LoganSquare.parseMap(json, SimpleModel.class));
reserialized = LoganSquare.serialize(simpleModelMap, SimpleModel.class);
} catch (Exception ignored) { }
ASSERT.that(json.equals(reserialized)).isTrue();
}
示例12: enumList
import com.bluelinelabs.logansquare.LoganSquare; //导入方法依赖的package包/类
@Test
public void enumList() {
String json = "{\"enum_array\":[\"TWO\",\"ONE\"],\"enum_list\":[\"ONE\",\"TWO\",\"ONE\"],\"enum_map\":{\"key\":\"ONE\"},\"enum_obj\":\"ONE\"}";
String serialized = null;
try {
LoganSquare.registerTypeConverter(TestEnum.class, new LsEnumTestConverter());
EnumListModel test = LoganSquare.parse(json, EnumListModel.class);
serialized = LoganSquare.serialize(test);
} catch (Exception ignored) { }
ASSERT.that(json.equals(serialized)).isTrue();
}
示例13: mixedObjectList
import com.bluelinelabs.logansquare.LoganSquare; //导入方法依赖的package包/类
@Test
public void mixedObjectList() {
String json = "[true,1,1.0,\"test1\",false,1000,1000000000,\"test2\",{\"subkey1\":1,\"subkey2\":\"string\"},[1,2,3]]";
String reserialized = null;
try {
List<Object> list = LoganSquare.parseList(json, Object.class);
reserialized = LoganSquare.serialize(list, Object.class);
} catch (Exception ignored) { }
ASSERT.that(json.equals(reserialized)).isTrue();
}
示例14: stringMap
import com.bluelinelabs.logansquare.LoganSquare; //导入方法依赖的package包/类
@Test
public void stringMap() {
String json = "{\"key1\":\"val1\",\"key2\":\"val2\",\"key3\":\"val3\"}";
String reserialized = null;
try {
Map<String, String> map = new TreeMap<>(LoganSquare.parseMap(json, String.class));
reserialized = LoganSquare.serialize(map, String.class);
} catch (Exception ignored) { }
ASSERT.that(json.equals(reserialized)).isTrue();
}
示例15: floatMap
import com.bluelinelabs.logansquare.LoganSquare; //导入方法依赖的package包/类
@Test
public void floatMap() {
String json = "{\"key1\":1.4,\"key2\":2.0,\"key3\":3.224}";
String reserialized = null;
try {
Map<String, Float> map = new TreeMap<>(LoganSquare.parseMap(json, Float.class));
reserialized = LoganSquare.serialize(map, Float.class);
} catch (Exception ignored) { }
ASSERT.that(json.equals(reserialized)).isTrue();
}