List of usage examples for com.google.gson JsonParseException JsonParseException
public JsonParseException(Throwable cause)
From source file:co.forsaken.projectindigo.utils.mojangtokens.DateTypeAdapter.java
License:Open Source License
@Override public Date deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { if (!(json instanceof JsonPrimitive)) { throw new JsonParseException("The date " + json + " is not a string!"); }/*from www.ja va 2 s . c o m*/ if (type != Date.class) { throw new IllegalArgumentException(getClass() + " cannot deserialize to " + type); } String value = json.getAsString(); synchronized (enUsFormat) { try { return enUsFormat.parse(value); } catch (ParseException e) { try { return iso8601Format.parse(value); } catch (ParseException e2) { try { String tmp = value.replace("Z", "+00:00"); return iso8601Format.parse(tmp.substring(0, 22) + tmp.substring(23)); } catch (ParseException e3) { throw new JsonSyntaxException("Invalid date " + value, e3); } } } } }
From source file:com.aaasec.sigserv.cscommon.json.DateTypeAdapter.java
License:EUPL
public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { if (!(json instanceof JsonPrimitive)) { throw new JsonParseException("The date should be a string value"); }/* w ww .ja v a 2 s .c om*/ try { return format.parse(json.getAsString()); } catch (ParseException e) { throw new JsonParseException(e); } }
From source file:com.addhen.voto.sdk.DateDeserializer.java
License:Apache License
@Override public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { // Determine whether date has time as well String[] dateTime = json.getAsString().trim().split(" "); try {/*from ww w .j a v a 2 s . c om*/ if (dateTime.length > 1) { return new SimpleDateFormat(DATE_FORMATS[1], Locale.US).parse(json.getAsString()); } return new SimpleDateFormat(DATE_FORMATS[0], Locale.US).parse(json.getAsString()); } catch (ParseException e) { e.printStackTrace(); } throw new JsonParseException("Unparseable date: \"" + json.getAsString() + "\". Supported formats: " + Arrays.toString(DATE_FORMATS)); }
From source file:com.alignace.chargeio.mapper.gson.adapter.IPaymentTypeAdapter.java
License:Apache License
private Type typeForName(final JsonElement typeElem) { Type type = null;/* w w w .java 2 s. c o m*/ try { String typeName = typeElem.getAsString(); if (typeName.equals("card")) type = Card.class; else if (typeName.equals("bank")) type = Bank.class; else type = Class.forName(typeElem.getAsString()); } catch (ClassNotFoundException e) { throw new JsonParseException(e); } return type; }
From source file:com.android.volley.DateFormatter.java
License:Open Source License
public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonParseException exception = null; final String value = json.getAsString(); for (DateFormat format : formats) try {// ww w. j ava2 s .c o m synchronized (format) { return format.parse(value); } } catch (ParseException e) { exception = new JsonParseException(e); } throw exception; }
From source file:com.appslandia.common.json.DateAdapter.java
License:Open Source License
@Override public java.util.Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { synchronized (this.parMutex) { try {/*from ww w . j a va 2 s.c o m*/ return new java.util.Date(this.parser.parse(json.getAsString()).getTime()); } catch (ParseException ex) { throw new JsonParseException(ex); } } }
From source file:com.appslandia.common.json.SqlDateAdapter.java
License:Open Source License
@Override public java.sql.Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { synchronized (this.parMutex) { try {//from www . jav a2 s . c o m return new java.sql.Date(this.parser.parse(json.getAsString()).getTime()); } catch (ParseException ex) { throw new JsonParseException(ex); } } }
From source file:com.appslandia.common.json.SqlDateTimeAdapter.java
License:Open Source License
@Override public java.sql.Timestamp deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { synchronized (this.parMutex) { try {//from w w w .j a va2 s . co m return new java.sql.Timestamp(this.parser.parse(json.getAsString()).getTime()); } catch (ParseException ex) { throw new JsonParseException(ex); } } }
From source file:com.appslandia.common.json.SqlTimeAdapter.java
License:Open Source License
@Override public java.sql.Time deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { synchronized (this.parMutex) { try {//from w w w .j ava 2 s .c o m return new java.sql.Time(this.parser.parse(json.getAsString()).getTime()); } catch (ParseException ex) { throw new JsonParseException(ex); } } }
From source file:com.arcbees.vcs.util.GsonDateTypeAdapter.java
License:Apache License
@Override public Date deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { String value = json.getAsJsonPrimitive().getAsString(); Matcher matcher = DATE_TIME_LONG_FORMAT_PATTERN.matcher(value); for (DateFormat dateFormat : dateFormats) { try {/*from w w w . java2 s .c o m*/ if (matcher.matches()) { value = value.replace(matcher.group(1), ""); } return dateFormat.parse(value); } catch (ParseException e) { } } try { return new Date(json.getAsJsonPrimitive().getAsLong()); } catch (NumberFormatException e) { throw new JsonParseException(e); } }