Java Code Examples for org.codehaus.jackson.JsonParser#getText()
The following examples show how to use
org.codehaus.jackson.JsonParser#getText() .
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: JsonSerdeUtils.java From incubator-hivemall with Apache License 2.0 | 6 votes |
@Nonnull private static Object parseValue(@Nonnull final JsonParser p) throws JsonParseException, IOException { final JsonToken t = p.getCurrentToken(); switch (t) { case VALUE_FALSE: return Boolean.FALSE; case VALUE_TRUE: return Boolean.TRUE; case VALUE_NULL: return null; case VALUE_STRING: return p.getText(); case VALUE_NUMBER_FLOAT: return p.getDoubleValue(); case VALUE_NUMBER_INT: return p.getIntValue(); default: throw new IOException("Unexpected token: " + t); } }
Example 2
Source File: CustomJsonDateDeserializer.java From jeecg with Apache License 2.0 | 6 votes |
@Override public Date deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { String text = jp.getText(); if (StringUtils.hasText(text)) { try { if (text.indexOf(":") == -1 && text.length() == 10) { return this.dateFormat.parse(text); } else if (text.indexOf(":") > 0 && text.length() == 19) { return this.datetimeFormat.parse(text); } else { throw new IllegalArgumentException("Could not parse date, date format is error "); } } catch (ParseException ex) { IllegalArgumentException iae = new IllegalArgumentException("Could not parse date: " + ex.getMessage()); iae.initCause(ex); throw iae; } } else { return null; } }
Example 3
Source File: JsonSerdeUtils.java From incubator-hivemall with Apache License 2.0 | 5 votes |
private static void populateRecord(@Nonnull final List<Object> r, @Nonnull final JsonToken token, @Nonnull final JsonParser p, @Nonnull final HCatSchema s) throws IOException { if (token != JsonToken.FIELD_NAME) { throw new IOException("Field name expected"); } String fieldName = p.getText(); Integer fpos = s.getPosition(fieldName); if (fpos == null) { fpos = getPositionFromHiveInternalColumnName(fieldName); if (fpos == -1) { skipValue(p); return; // unknown field, we return. We'll continue from the next field onwards. } // If we get past this, then the column name did match the hive pattern for an internal // column name, such as _col0, etc, so it *MUST* match the schema for the appropriate column. // This means people can't use arbitrary column names such as _col0, and expect us to ignore it // if we find it. if (!fieldName.equalsIgnoreCase(getHiveInternalColumnName(fpos))) { throw new IOException("Hive internal column name (" + fieldName + ") and position encoding (" + fpos + ") for the column name are at odds"); } // If we reached here, then we were successful at finding an alternate internal // column mapping, and we're about to proceed. } HCatFieldSchema hcatFieldSchema = s.getFields().get(fpos); Object currField = extractCurrentField(p, hcatFieldSchema, false); r.set(fpos, currField); }
Example 4
Source File: CustomJsonDateDeserializer.java From demo-restWS-spring-jersey-jpa2-hibernate with MIT License | 5 votes |
@Override public Date deserialize(JsonParser jsonparser, DeserializationContext context) throws IOException, JsonProcessingException { SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy HH:mm"); String date = jsonparser.getText(); try { return format.parse(date); } catch (ParseException e) { throw new RuntimeException(e); } }
Example 5
Source File: JsonDateDeSerializer.java From AIDR with GNU Affero General Public License v3.0 | 5 votes |
@Override public Date deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { String date = jp.getText(); if(date!= null && !date.equals("")){ try { return dateFormat.parse(date); } catch (ParseException e) { throw new RuntimeException(e); } } return null; }
Example 6
Source File: JsonDateDeSerializer.java From AIDR with GNU Affero General Public License v3.0 | 5 votes |
@Override public Date deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { String date = jp.getText(); if(date!= null && !date.equals("")){ try { return dateFormat.parse(date); } catch (ParseException e) { logger.error("ParfseException for the date:"+date,e); throw new RuntimeException(e); } } return null; }
Example 7
Source File: StringDeserializer.java From test-data-generator with Apache License 2.0 | 4 votes |
@Override public String deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { String str = jsonParser.getText(); return formatString(str); }
Example 8
Source File: BackendResponse.java From ReactiveLab with Apache License 2.0 | 4 votes |
private static BackendResponse parseBackendResponse(JsonParser parser) throws IOException { try { // Sanity check: verify that we got "Json Object": if (parser.nextToken() != JsonToken.START_OBJECT) { throw new IOException("Expected data to start with an Object"); } long responseKey = 0; int delay = 0; int numItems = 0; int itemSize = 0; String[] items = null; JsonToken current; while (parser.nextToken() != JsonToken.END_OBJECT) { String fieldName = parser.getCurrentName(); // advance current = parser.nextToken(); if (fieldName.equals("responseKey")) { responseKey = parser.getLongValue(); } else if (fieldName.equals("delay")) { delay = parser.getIntValue(); } else if (fieldName.equals("itemSize")) { itemSize = parser.getIntValue(); } else if (fieldName.equals("numItems")) { numItems = parser.getIntValue(); } else if (fieldName.equals("items")) { // expect numItems to be populated before hitting this if (numItems == 0) { throw new IllegalStateException("Expected numItems > 0"); } items = new String[numItems]; if (current == JsonToken.START_ARRAY) { int j = 0; // For each of the records in the array while (parser.nextToken() != JsonToken.END_ARRAY) { items[j++] = parser.getText(); } } else { // System.out.println("Error: items should be an array: skipping."); parser.skipChildren(); } } } return new BackendResponse(responseKey, delay, numItems, itemSize, items); } finally { parser.close(); } }
Example 9
Source File: BackendResponse.java From WSPerfLab with Apache License 2.0 | 4 votes |
public static BackendResponse parseBackendResponse(JsonParser parser) throws IOException { try { // Sanity check: verify that we got "Json Object": if (parser.nextToken() != JsonToken.START_OBJECT) { throw new IOException("Expected data to start with an Object"); } long responseKey = 0; int delay = 0; int numItems = 0; int itemSize = 0; String[] items = null; JsonToken current; while (parser.nextToken() != JsonToken.END_OBJECT) { String fieldName = parser.getCurrentName(); // advance current = parser.nextToken(); if (fieldName.equals("responseKey")) { responseKey = parser.getLongValue(); } else if (fieldName.equals("delay")) { delay = parser.getIntValue(); } else if (fieldName.equals("itemSize")) { itemSize = parser.getIntValue(); } else if (fieldName.equals("numItems")) { numItems = parser.getIntValue(); } else if (fieldName.equals("items")) { // expect numItems to be populated before hitting this if (numItems == 0) { throw new IllegalStateException("Expected numItems > 0"); } items = new String[numItems]; if (current == JsonToken.START_ARRAY) { int j = 0; // For each of the records in the array while (parser.nextToken() != JsonToken.END_ARRAY) { items[j++] = parser.getText(); } } else { // System.out.println("Error: items should be an array: skipping."); parser.skipChildren(); } } } return new BackendResponse(responseKey, delay, numItems, itemSize, items); } finally { parser.close(); } }