当前位置: 首页>>代码示例>>Java>>正文


Java LoganSquare.serialize方法代码示例

本文整理汇总了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();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:RoundTripTests.java

示例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);
    }
}
 
开发者ID:getsadzeg,项目名称:AreYouAlive,代码行数:21,代码来源:LoganSquareConverter.java

示例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;
    }
}
 
开发者ID:8tory,项目名称:json2notification,代码行数:18,代码来源:Json2Notification.java

示例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);
  }
}
 
开发者ID:sockeqwe,项目名称:SecureBitcoinWallet,代码行数:22,代码来源:LoganSquareConverter.java

示例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);
}
 
开发者ID:pavlospt,项目名称:RxIAPv3,代码行数:21,代码来源:SkuDetailsJsonParsingTest.java

示例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);
	}
}
 
开发者ID:yongjhih,项目名称:converter-logansquare-retrofit,代码行数:21,代码来源:LoganSquareConverter.java

示例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);
    }
}
 
开发者ID:dinosaurwithakatana,项目名称:hacker-news-android,代码行数:24,代码来源:LoganSquareConvertor.java

示例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();
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:LoganSquareSerializer.java

示例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();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:RoundTripTests.java

示例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();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:RoundTripTests.java

示例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();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:14,代码来源:RoundTripTests.java

示例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();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:14,代码来源:RoundTripTests.java

示例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();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:RoundTripTests.java

示例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();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:RoundTripTests.java

示例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();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:RoundTripTests.java


注:本文中的com.bluelinelabs.logansquare.LoganSquare.serialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。