Java Code Examples for com.google.gson.internal.bind.util.ISO8601Utils#format()

The following examples show how to use com.google.gson.internal.bind.util.ISO8601Utils#format() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Tags.java    From intra42 with Apache License 2.0 6 votes vote down vote up
@Nullable
public static List<Tags> getTagsUpdate(ApiService api, Date updateAtStart, Date updateAtEnd) {
    List<Tags> list = new ArrayList<>();
    int pageSize = 100;
    String range = ISO8601Utils.format(updateAtStart) + "," + ISO8601Utils.format(updateAtEnd);

    try {
        Response<List<Tags>> response = api.getTags(range, pageSize, Pagination.getPage(list, pageSize)).execute();
        if (!Tools.apiIsSuccessfulNoThrow(response))
            return null;

        int total = Integer.decode(response.headers().get("X-Total"));
        list.addAll(response.body());

        while (list.size() < total) {
            response = api.getTags(range, pageSize, Pagination.getPage(list, pageSize)).execute();
            if (!Tools.apiIsSuccessfulNoThrow(response))
                return null;
            list.addAll(response.body());
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return list;
}
 
Example 2
Source File: JSON.java    From huaweicloud-cs-sdk with Apache License 2.0 5 votes vote down vote up
@Override
public void write(JsonWriter out, Date date) throws IOException {
    if (date == null) {
        out.nullValue();
    } else {
        String value;
        if (dateFormat != null) {
            value = dateFormat.format(date);
        } else {
            value = ISO8601Utils.format(date, true);
        }
        out.value(value);
    }
}
 
Example 3
Source File: JSON.java    From oxd with Apache License 2.0 5 votes vote down vote up
@Override
public void write(JsonWriter out, Date date) throws IOException {
    if (date == null) {
        out.nullValue();
    } else {
        String value;
        if (dateFormat != null) {
            value = dateFormat.format(date);
        } else {
            value = ISO8601Utils.format(date, true);
        }
        out.value(value);
    }
}
 
Example 4
Source File: JSON.java    From director-sdk with Apache License 2.0 5 votes vote down vote up
@Override
public void write(JsonWriter out, Date date) throws IOException {
    if (date == null) {
        out.nullValue();
    } else {
        String value;
        if (dateFormat != null) {
            value = dateFormat.format(date);
        } else {
            value = ISO8601Utils.format(date, true);
        }
        out.value(value);
    }
}
 
Example 5
Source File: JSON.java    From eve-esi with Apache License 2.0 5 votes vote down vote up
@Override
public void write(JsonWriter out, Date date) throws IOException {
    if (date == null) {
        out.nullValue();
    } else {
        String value;
        if (dateFormat != null) {
            value = dateFormat.format(date);
        } else {
            value = ISO8601Utils.format(date, true);
        }
        out.value(value);
    }
}
 
Example 6
Source File: JSON.java    From swagger-aem with Apache License 2.0 5 votes vote down vote up
@Override
public void write(JsonWriter out, Date date) throws IOException {
    if (date == null) {
        out.nullValue();
    } else {
        String value;
        if (dateFormat != null) {
            value = dateFormat.format(date);
        } else {
            value = ISO8601Utils.format(date, true);
        }
        out.value(value);
    }
}
 
Example 7
Source File: JSON.java    From swaggy-jenkins with MIT License 5 votes vote down vote up
@Override
public void write(JsonWriter out, Date date) throws IOException {
    if (date == null) {
        out.nullValue();
    } else {
        String value;
        if (dateFormat != null) {
            value = dateFormat.format(date);
        } else {
            value = ISO8601Utils.format(date, true);
        }
        out.value(value);
    }
}
 
Example 8
Source File: JSON.java    From nifi-swagger-client with Apache License 2.0 5 votes vote down vote up
@Override
public void write(JsonWriter out, Date date) throws IOException {
    if (date == null) {
        out.nullValue();
    } else {
        String value;
        if (dateFormat != null) {
            value = dateFormat.format(date);
        } else {
            value = ISO8601Utils.format(date, true);
        }
        out.value(value);
    }
}
 
Example 9
Source File: JSON.java    From android with MIT License 5 votes vote down vote up
@Override
public void write(JsonWriter out, Date date) throws IOException {
    if (date == null) {
        out.nullValue();
    } else {
        String value;
        if (dateFormat != null) {
            value = dateFormat.format(date);
        } else {
            value = ISO8601Utils.format(date, true);
        }
        out.value(value);
    }
}
 
Example 10
Source File: JSON.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@Override
public void write(JsonWriter out, Date date) throws IOException {
    if (date == null) {
        out.nullValue();
    } else {
        String value;
        if (dateFormat != null) {
            value = dateFormat.format(date);
        } else {
            value = ISO8601Utils.format(date, true);
        }
        out.value(value);
    }
}
 
Example 11
Source File: JSON.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@Override
public void write(JsonWriter out, Date date) throws IOException {
    if (date == null) {
        out.nullValue();
    } else {
        String value;
        if (dateFormat != null) {
            value = dateFormat.format(date);
        } else {
            value = ISO8601Utils.format(date, true);
        }
        out.value(value);
    }
}
 
Example 12
Source File: JSON.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@Override
public void write(JsonWriter out, Date date) throws IOException {
    if (date == null) {
        out.nullValue();
    } else {
        String value;
        if (dateFormat != null) {
            value = dateFormat.format(date);
        } else {
            value = ISO8601Utils.format(date, true);
        }
        out.value(value);
    }
}
 
Example 13
Source File: JSON.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@Override
public void write(JsonWriter out, Date date) throws IOException {
    if (date == null) {
        out.nullValue();
    } else {
        String value;
        if (dateFormat != null) {
            value = dateFormat.format(date);
        } else {
            value = ISO8601Utils.format(date, true);
        }
        out.value(value);
    }
}
 
Example 14
Source File: JSON.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@Override
public void write(JsonWriter out, Date date) throws IOException {
    if (date == null) {
        out.nullValue();
    } else {
        String value;
        if (dateFormat != null) {
            value = dateFormat.format(date);
        } else {
            value = ISO8601Utils.format(date, true);
        }
        out.value(value);
    }
}
 
Example 15
Source File: JSON.java    From influxdb-client-java with MIT License 5 votes vote down vote up
@Override
public void write(JsonWriter out, Date date) throws IOException {
    if (date == null) {
        out.nullValue();
    } else {
        String value;
        if (dateFormat != null) {
            value = dateFormat.format(date);
        } else {
            value = ISO8601Utils.format(date, true);
        }
        out.value(value);
    }
}
 
Example 16
Source File: MaintenanceModeService.java    From gocd with Apache License 2.0 4 votes vote down vote up
public String updatedOn() {
    return ISO8601Utils.format(updatedOnTimeStamp(), false, UTC);
}
 
Example 17
Source File: ServiceGenerator.java    From intra42 with Apache License 2.0 4 votes vote down vote up
static public Gson getGson() {

        class DateDeserializer implements JsonDeserializer<Date> {

            private final String TAG = DateDeserializer.class.getSimpleName();

            @Override
            public java.util.Date deserialize(JsonElement element, Type arg1, JsonDeserializationContext arg2) throws JsonParseException {
                String date = element.getAsString();
                Date returnDate = null;

                try {
                    returnDate = ISO8601Utils.parse(date, new ParsePosition(0));
                } catch (ParseException | IllegalArgumentException e) {
                    Log.e(TAG, "Failed to parse dateString: (" + date + "),  due to:", e);
                }
                return returnDate;
            }
        }

        class DateSerializer implements JsonSerializer<Date> {

            @Override
            public JsonElement serialize(java.util.Date src, Type typeOfSrc, JsonSerializationContext context) {
                String dateFormatAsString = ISO8601Utils.format(src, false, TimeZone.getTimeZone("GMT"));
                return new JsonPrimitive(dateFormatAsString);
            }

        }

        return new GsonBuilder()
                .setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
                .registerTypeAdapter(Slots.class, new Slots.SlotsDeserializer())
                .registerTypeAdapter(Slots.class, new Slots.SlotsSerializer())
                .registerTypeAdapter(java.util.Date.class, new DateDeserializer())
                .registerTypeAdapter(java.util.Date.class, new DateSerializer())
                .registerTypeAdapter(UsersLTE.class, new UsersLTE.UserLTEDeserializer())

                .registerTypeAdapter(Messages.UserVotes.class, new Messages.UserVotes.UserVotesDeserializer())

                .registerTypeAdapter(UsersLTE.getListType(), new UsersLTE.ListUserLTEDeserializer())

//                .registerTypeAdapter(ScaleTeams.class, new ScaleTeams.ScaleTeamsDeserializer())
                .create();
    }
 
Example 18
Source File: JsonOutputWriter.java    From gocd with Apache License 2.0 4 votes vote down vote up
public static String jsonDate(Date value) {
    return value == null ? null : ISO8601Utils.format(value, false, UTC);
}
 
Example 19
Source File: DateUtil.java    From edx-app-android with Apache License 2.0 4 votes vote down vote up
/**
 * @return The current date and time in a ISO 8601 compliant format.
 */
public static String getCurrentTimeStamp(){
    return ISO8601Utils.format(new Date(), true); // Find todays date
}
 
Example 20
Source File: Iso8601Format.java    From yandex-money-sdk-java with MIT License 2 votes vote down vote up
/**
 * Formats date time to ISO 8601 string.
 *
 * @param dateTime date time to format
 * @return formatted string
 */
public static String format(DateTime dateTime) {
    Calendar calendar = checkNotNull(dateTime, "dateTime").getCalendar();
    return ISO8601Utils.format(calendar.getTime(), true, calendar.getTimeZone());
}