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


Java LoganSquare类代码示例

本文整理汇总了Java中com.bluelinelabs.logansquare.LoganSquare的典型用法代码示例。如果您正苦于以下问题:Java LoganSquare类的具体用法?Java LoganSquare怎么用?Java LoganSquare使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


LoganSquare类属于com.bluelinelabs.logansquare包,在下文中一共展示了LoganSquare类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getResponsesToParse

import com.bluelinelabs.logansquare.LoganSquare; //导入依赖的package包/类
private List<Response> getResponsesToParse() {
    List<Response> responses = new ArrayList<>();

    try {
        for (String jsonString : mJsonStringsToParse) {
            responses.add(LoganSquare.parse(jsonString, Response.class));
        }
    } catch (Exception e) {
        new AlertDialog.Builder(this)
                .setTitle("Error")
                .setMessage("The serializable objects were not able to load properly. These tests won't work until you completely kill this demo app and restart it.")
                .setPositiveButton("OK", null)
                .show();
    }

    return responses;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:MainActivity.java

示例2: addUsedTypeConverterMethods

import com.bluelinelabs.logansquare.LoganSquare; //导入依赖的package包/类
private void addUsedTypeConverterMethods(TypeSpec.Builder builder) {
    Set<TypeName> usedTypeConverters = new HashSet<>();

    for (JsonFieldHolder holder : mJsonObjectHolder.fieldMap.values()) {
        usedTypeConverters.addAll(holder.type.getUsedTypeConverters());
    }

    for (TypeName usedTypeConverter : usedTypeConverters) {
        final String variableName = getTypeConverterVariableName(usedTypeConverter);
        builder.addField(FieldSpec.builder(ParameterizedTypeName.get(ClassName.get(TypeConverter.class), usedTypeConverter), variableName)
                .addModifiers(Modifier.PRIVATE, Modifier.STATIC)
                .build()
        );

        builder.addMethod(MethodSpec.methodBuilder(getTypeConverterGetter(usedTypeConverter))
                .addModifiers(Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL)
                .returns(ParameterizedTypeName.get(ClassName.get(TypeConverter.class), usedTypeConverter))
                .beginControlFlow("if ($L == null)", variableName)
                .addStatement("$L = $T.typeConverterFor($T.class)", variableName, LoganSquare.class, usedTypeConverter)
                .endControlFlow()
                .addStatement("return $L", variableName)
                .build()
        );
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:ObjectMapperInjector.java

示例3: serialize

import com.bluelinelabs.logansquare.LoganSquare; //导入依赖的package包/类
@Override
public void serialize(Builder builder, int depth, String fieldName, List<String> processedFieldNames, String getter, boolean isObjectProperty, boolean checkIfNull, boolean writeIfNull, boolean writeCollectionElementIfNull) {
    if (!mTypeName.isPrimitive() && checkIfNull) {
        builder.beginControlFlow("if ($L != null)", getter);
    }

    builder.addStatement("$T.typeConverterFor($T.class).serialize($L, $S, $L, $L)", LoganSquare.class, mTypeName, getter, isObjectProperty
            ? fieldName : null, isObjectProperty, JSON_GENERATOR_VARIABLE_NAME);

    if (!mTypeName.isPrimitive() && checkIfNull) {
        if (writeIfNull) {
            builder.nextControlFlow("else");

            if (isObjectProperty) {
                builder.addStatement("$L.writeFieldName($S)", JSON_GENERATOR_VARIABLE_NAME, fieldName);
            }
            builder.addStatement("$L.writeNull()", JSON_GENERATOR_VARIABLE_NAME);
        }
        builder.endControlFlow();
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:DynamicFieldType.java

示例4: simpleObjectListWithNulls

import com.bluelinelabs.logansquare.LoganSquare; //导入依赖的package包/类
@Test
public void simpleObjectListWithNulls() {
    String json = "[{\"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\"}," +
            "{\"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\"}," +
            "{\"date\":null,\"string\":\"testString2\",\"test_double\":342.0,\"test_double_obj\":null,\"test_float\":898.0,\"test_float_obj\":null,\"test_int\":32,\"test_int_obj\":null,\"test_long\":932,\"test_long_obj\":null,\"test_string\":null}," +
            "null," +
            "null]";

    String reserialized = null;
    try {
        List<SimpleModel> simpleModels = LoganSquare.parseList(json, SimpleModel.class);
        reserialized = LoganSquare.serialize(simpleModels, SimpleModel.class);
    } catch (Exception ignored) { }

    ASSERT.that(json.equals(reserialized)).isTrue();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:RoundTripTests.java

示例5: simpleObjectMapWithNulls

import com.bluelinelabs.logansquare.LoganSquare; //导入依赖的package包/类
@Test
public void simpleObjectMapWithNulls() {
    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\"}," +
            "\"obj3\":{\"date\":null,\"string\":\"testString2\",\"test_double\":342.0,\"test_double_obj\":null,\"test_float\":898.0,\"test_float_obj\":null,\"test_int\":32,\"test_int_obj\":null,\"test_long\":932,\"test_long_obj\":null,\"test_string\":null}," +
            "\"obj4\":null}";

    String reserialized = null;
    try {
        Map<String, SimpleModel> simpleModelMap = LoganSquare.parseMap(json, SimpleModel.class);
        TreeMap<String, SimpleModel> sortedMap = new TreeMap<>();
        sortedMap.put("obj1", simpleModelMap.get("obj1"));
        sortedMap.put("obj2", simpleModelMap.get("obj2"));
        sortedMap.put("obj3", simpleModelMap.get("obj3"));
        sortedMap.put("obj4", simpleModelMap.get("obj4"));

        reserialized = LoganSquare.serialize(sortedMap, SimpleModel.class);
    } catch (Exception ignored) { }

    ASSERT.that(json.equals(reserialized)).isTrue();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:RoundTripTests.java

示例6: simpleObjectMapWithoutNulls

import com.bluelinelabs.logansquare.LoganSquare; //导入依赖的package包/类
@Test
public void simpleObjectMapWithoutNulls() {
    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\"}," +
            "\"obj3\":{\"string\":\"testString2\",\"test_double\":342.0,\"test_float\":898.0,\"test_int\":32,\"test_long\":932}," +
            "\"obj4\":null}";

    String reserialized = null;
    try {
        Map<String, SimpleModelWithoutNullObjects> simpleModelMap = LoganSquare.parseMap(json, SimpleModelWithoutNullObjects.class);
        TreeMap<String, SimpleModelWithoutNullObjects> sortedMap = new TreeMap<>();
        sortedMap.put("obj1", simpleModelMap.get("obj1"));
        sortedMap.put("obj2", simpleModelMap.get("obj2"));
        sortedMap.put("obj3", simpleModelMap.get("obj3"));
        sortedMap.put("obj4", simpleModelMap.get("obj4"));

        reserialized = LoganSquare.serialize(sortedMap, SimpleModelWithoutNullObjects.class);
    } catch (Exception ignored) { }

    ASSERT.that(json.equals(reserialized)).isTrue();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:RoundTripTests.java

示例7: 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

示例8: parse

import com.bluelinelabs.logansquare.LoganSquare; //导入依赖的package包/类
@Override
public Object parse(JsonParser jsonParser) throws IOException {
    switch (jsonParser.getCurrentToken()) {
        case VALUE_NULL:
            return null;
        case VALUE_FALSE:
            return false;
        case VALUE_TRUE:
            return true;
        case VALUE_NUMBER_FLOAT:
            return jsonParser.getDoubleValue();
        case VALUE_NUMBER_INT:
            return jsonParser.getLongValue();
        case VALUE_STRING:
            return jsonParser.getText();
        case VALUE_EMBEDDED_OBJECT:
            return LoganSquare.mapperFor(Map.class).parse(jsonParser);
        case START_OBJECT:
            return LoganSquare.mapperFor(Map.class).parse(jsonParser);
        case START_ARRAY:
            return LoganSquare.mapperFor(List.class).parse(jsonParser);
        default:
            throw new RuntimeException("Invalid json token encountered: " + jsonParser.getCurrentToken());
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:ObjectMapper.java

示例9: parseList

import com.bluelinelabs.logansquare.LoganSquare; //导入依赖的package包/类
@Nullable
public static List parseList(@NonNull InputStream stream) {
    List list = null;
    JsonStructure jsonStructure = CandyBarApplication.getConfiguration().getWallpaperJsonStructure();

    try {
        if (jsonStructure.getArrayName() == null) {
            list = LoganSquare.parseList(stream, Map.class);
        } else {
            Map<String, List> map = LoganSquare.parseMap(stream, List.class);
            list = map.get(jsonStructure.getArrayName());
        }
    } catch (IOException e) {
        LogUtil.e(Log.getStackTraceString(e));
    }
    return list;
}
 
开发者ID:danimahardhika,项目名称:candybar-library,代码行数:18,代码来源:JsonHelper.java

示例10: sendMessage

import com.bluelinelabs.logansquare.LoganSquare; //导入依赖的package包/类
<Req extends Request, Resp extends Response> boolean sendMessage(Req message, Class<Resp> respCls,
                                                                 Callback<Resp> callback) {
    if (isClosed()) return false;
    try {
        final List<Req> messageList = Collections.singletonList(message);
        //noinspection unchecked
        final JsonMapper<Req> mapper = (JsonMapper<Req>) LoganSquare.mapperFor(message.getClass());
        final String messageJson = mapper.serialize(messageList);
        final String id = message.getId();
        resultHandlers.put(id, new SendResultHandler<>(id, respCls, callback));
        webSocket.sendMessage(RequestBody.create(WebSocket.TEXT, messageJson));
    } catch (IOException e) {
        faye.unconnected(e, -1, null);
        disconnect();
        return false;
    }
    return true;
}
 
开发者ID:mariotaku,项目名称:OkFaye,代码行数:19,代码来源:FayeImpl.java

示例11: onMessage

import com.bluelinelabs.logansquare.LoganSquare; //导入依赖的package包/类
@Override
public void onMessage(ResponseBody message) throws IOException {
    final String json = message.string();
    List<Response> responseList = LoganSquare.parseList(json, Response.class);
    if (responseList != null) {
        for (Response response : responseList) {
            Advice advice = response.getAdvice();
            if (advice != null) {
                faye.handleAdvice(advice);
            }
            final String channel = response.getChannel(), id = response.getId();
            Callback<String> callback = messageCallbacks.get(channel);
            if (callback != null) {
                callback.callback(response.getData());
            }
            SendResultHandler<?> handler = resultHandlers.remove(id);
            if (handler != null) {
                handler.call(json);
            }
        }
    }
    reschedulePing();
}
 
开发者ID:mariotaku,项目名称:OkFaye,代码行数:24,代码来源:FayeImpl.java

示例12: test_Parse_JSONRepo_ParsesRepoDTO

import com.bluelinelabs.logansquare.LoganSquare; //导入依赖的package包/类
@Frutilla(
        Given = "A single GitHub repo from a JSON file",
        When = "Parsing this content with LoganSquare",
        Then = "It should have parsed a repo named \"git-consortium\""
)
@Test
public void test_Parse_JSONRepo_ParsesRepoDTO() throws IOException {
    String lsRepoData;
    Given:
    {
        lsRepoData = mLocalifyClient.localify().loadRawFile(R.raw.repo_octocat);
    }

    DTORepo loRepoDTO;
    When:
    {
        loRepoDTO = LoganSquare.parse(lsRepoData, DTORepo.class);
    }

    Then:
    {
        assertThat(loRepoDTO).isNotNull();
        assertThat(loRepoDTO.name).isEqualTo("git-consortium");
    }
}
 
开发者ID:RoRoche,项目名称:AndroidStarterAlt,代码行数:26,代码来源:TestParsing.java

示例13: test_Parse_JSONArrayRepo_ParsesRepoAsArrayDTO

import com.bluelinelabs.logansquare.LoganSquare; //导入依赖的package包/类
@Frutilla(
        Given = "Multiple GitHub repos from a JSON file",
        When = "Parsing this content with LoganSquare",
        Then = "It should have parsed a repo named \"git-consortium\""
)
@Test
public void test_Parse_JSONArrayRepo_ParsesRepoAsArrayDTO() throws IOException {
    String lsRepoDataAsArray;
    Given:
    {
        lsRepoDataAsArray = mLocalifyClient.localify().loadRawFile(R.raw.repos_octocat);
    }

    List<DTORepo> lloRepoAsArrayDTO;
    When:
    {
        lloRepoAsArrayDTO = LoganSquare.parseList(lsRepoDataAsArray, DTORepo.class);
    }

    Then:
    {
        assertThat(lloRepoAsArrayDTO).hasSize(1);
        assertThat(lloRepoAsArrayDTO.get(0).name).isEqualTo("git-consortium");
    }
}
 
开发者ID:RoRoche,项目名称:AndroidStarterAlt,代码行数:26,代码来源:TestParsing.java

示例14: fromBody

import com.bluelinelabs.logansquare.LoganSquare; //导入依赖的package包/类
@Override public Object fromBody(TypedInput body, Type type) throws ConversionException {
    try {
        // Check if the type contains a parametrized list
        if (ParameterizedType.class.isAssignableFrom(type.getClass())) {
            // Grab the actual type parameter from the parametrized list and delegate to LoganSquare
            ParameterizedType parameterized = (ParameterizedType) type;
            return LoganSquare.parseList(body.in(), (Class) parameterized.getActualTypeArguments()[0]);

        } else {
            // Single elements get parsed immediately
            return LoganSquare.parse(body.in(), (Class) type);
        }
    } catch (Exception e) {
        throw new ConversionException(e);
    }
}
 
开发者ID:getsadzeg,项目名称:AreYouAlive,代码行数:17,代码来源:LoganSquareConverter.java

示例15: 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


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