private void writeObject(
     ContentValues values, Object object, String columnName, ParameterizedType fieldType)
     throws IOException {
   if (object == null) return;
   final Type rawType = fieldType.getRawType();
   if (!(rawType instanceof Class)) throw new UnsupportedOperationException();
   final Class rawCls = (Class) rawType;
   if (List.class.isAssignableFrom(rawCls)) {
     values.put(
         columnName,
         LoganSquare.serialize((List) object, (Class) fieldType.getActualTypeArguments()[0]));
   } else if (Map.class.isAssignableFrom(rawCls)) {
     //noinspection unchecked
     values.put(
         columnName,
         LoganSquare.serialize((Map) object, (Class) fieldType.getActualTypeArguments()[1]));
   } else if (rawCls.isArray()) {
     final Class componentType = rawCls.getComponentType();
     values.put(
         columnName,
         LoganSquare.serialize((List) Arrays.asList((Object[]) object), componentType));
   } else {
     values.put(columnName, LoganSquare.serialize(object));
   }
 }
예제 #2
0
파일: Parser.java 프로젝트: netantskr/Note
 public static <D> D parse(InputStream is, Class<D> parseClass) throws ParseException {
   try {
     return LoganSquare.parse(is, parseClass);
   } catch (Exception e) {
     throw new ParseException(e);
   }
 }
예제 #3
0
 public static ParcelableCardEntity fromJSONString(final String json) {
   if (TextUtils.isEmpty(json)) return null;
   try {
     return LoganSquare.parse(json, ParcelableCardEntity.class);
   } catch (final IOException e) {
     return null;
   }
 }
 private Object getObject(Cursor cursor, int columnIndex, ParameterizedType fieldType)
     throws IOException {
   final Type rawType = fieldType.getRawType();
   if (!(rawType instanceof Class)) throw new UnsupportedOperationException();
   final Class rawCls = (Class) rawType;
   final String string = cursor.getString(columnIndex);
   if (TextUtils.isEmpty(string)) return null;
   if (List.class.isAssignableFrom(rawCls)) {
     // Parse list
     return LoganSquare.parseList(string, (Class) fieldType.getActualTypeArguments()[0]);
   } else if (Map.class.isAssignableFrom(rawCls)) {
     return LoganSquare.parseMap(string, (Class) fieldType.getActualTypeArguments()[1]);
   } else if (rawCls.isArray()) {
     final Class componentType = rawCls.getComponentType();
     List<?> list = LoganSquare.parseList(string, componentType);
     return list.toArray((Object[]) Array.newInstance(componentType, list.size()));
   }
   return LoganSquare.parse(string, rawCls);
 }
예제 #5
0
  public static class Converter implements TypeConverter<IDs> {

    private static final JsonMapper<IDs> IDS_JSON_MAPPER = LoganSquare.mapperFor(IDs.class);

    @Override
    public IDs parse(JsonParser jsonParser) throws IOException {
      return IDS_JSON_MAPPER.parse(jsonParser);
    }

    @Override
    public void serialize(
        IDs object, String fieldName, boolean writeFieldNameForObject, JsonGenerator jsonGenerator)
        throws IOException {
      if (writeFieldNameForObject) {
        jsonGenerator.writeFieldName(fieldName);
      }
      IDS_JSON_MAPPER.serialize(object, jsonGenerator, true);
    }
  }
 private MoviesList generateMoviesList() throws IOException {
   InputStream inputStream = TestResourceLoader.load(this, "tmdb_popular_1.json");
   return MoviesList.create(LoganSquare.parse(inputStream, MoviesListResponse.class));
 }