org.codehaus.jackson.JsonParseException Java Examples
The following examples show how to use
org.codehaus.jackson.JsonParseException.
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: DidReferenceResolutionTest.java From secure-data-service with Apache License 2.0 | 6 votes |
@Test public void resolvesSessionRefDidsInCourseOfferingCorrectly() throws JsonParseException, JsonMappingException, IOException { NeutralRecordEntity entity = loadEntity("didTestEntities/courseOffering.json"); resolveInternalId(entity); Map<String, String> edOrgNaturalKeys = new HashMap<String, String>(); edOrgNaturalKeys.put("stateOrganizationId", "testSchoolId"); String edOrgId = generateExpectedDid(edOrgNaturalKeys, TENANT_ID, "educationOrganization", null); Map<String, String> sessionNaturalKeys = new HashMap<String, String>(); sessionNaturalKeys.put("schoolId", edOrgId); sessionNaturalKeys.put("sessionId", "theSessionName"); checkId(entity, "SessionReference", sessionNaturalKeys, "session"); }
Example #2
Source File: DelegatingAvroKeyInputFormat.java From incubator-pinot with Apache License 2.0 | 6 votes |
public static String getSourceNameFromPath(FileSplit fileSplit, Configuration configuration) throws IOException, JsonParseException, JsonMappingException { String content = configuration.get("schema.path.mapping"); Map<String, String> schemaPathMapping = new ObjectMapper().readValue(content, MAP_STRING_STRING_TYPE); LOGGER.info("Schema Path Mapping: {}", schemaPathMapping); String sourceName = null; for (String path : schemaPathMapping.keySet()) { if (fileSplit.getPath().toString().indexOf(path) > -1) { sourceName = schemaPathMapping.get(path); break; } } return sourceName; }
Example #3
Source File: AbstractSiteToSiteReportingTask.java From nifi with Apache License 2.0 | 6 votes |
public JsonRecordReader(final InputStream in, RecordSchema recordSchema) throws IOException, MalformedRecordException { this.recordSchema = recordSchema; try { jsonParser = new JsonFactory().createJsonParser(in); jsonParser.setCodec(new ObjectMapper()); JsonToken token = jsonParser.nextToken(); if (token == JsonToken.START_ARRAY) { array = true; token = jsonParser.nextToken(); } else { array = false; } if (token == JsonToken.START_OBJECT) { firstJsonNode = jsonParser.readValueAsTree(); } else { firstJsonNode = null; } } catch (final JsonParseException e) { throw new MalformedRecordException("Could not parse data as JSON", e); } }
Example #4
Source File: SiteToSiteRestApiClient.java From localization_nifi with Apache License 2.0 | 6 votes |
private TransactionResultEntity readResponse(final InputStream inputStream) throws IOException { final ByteArrayOutputStream bos = new ByteArrayOutputStream(); StreamUtils.copy(inputStream, bos); String responseMessage = null; try { responseMessage = new String(bos.toByteArray(), "UTF-8"); logger.debug("readResponse responseMessage={}", responseMessage); final ObjectMapper mapper = new ObjectMapper(); return mapper.readValue(responseMessage, TransactionResultEntity.class); } catch (JsonParseException | JsonMappingException e) { if (logger.isDebugEnabled()) { logger.debug("Failed to parse JSON.", e); } final TransactionResultEntity entity = new TransactionResultEntity(); entity.setResponseCode(ResponseCode.ABORT.getCode()); entity.setMessage(responseMessage); return entity; } }
Example #5
Source File: DelegatingAvroKeyInputFormat.java From incubator-pinot with Apache License 2.0 | 6 votes |
public static String getSourceNameFromPath(FileSplit fileSplit, Configuration configuration) throws IOException, JsonParseException, JsonMappingException { String content = configuration.get("schema.path.mapping"); Map<String, String> schemaPathMapping = new ObjectMapper().readValue(content, MAP_STRING_STRING_TYPE); LOGGER.info("Schema Path Mapping: {}", schemaPathMapping); String sourceName = null; for (String path : schemaPathMapping.keySet()) { if (fileSplit.getPath().toString().indexOf(path) > -1) { sourceName = schemaPathMapping.get(path); break; } } return sourceName; }
Example #6
Source File: JSONUtil.java From kardio with Apache License 2.0 | 6 votes |
/** * Function to validate the json string * @param json * @return */ public static boolean isJSONValid(String json) { boolean valid = false; try { final JsonParser parser = new ObjectMapper().getJsonFactory() .createJsonParser(json); while (parser.nextToken() != null) { } valid = true; } catch (JsonParseException jpe) { logger.error("Invalid JSON String JsonParseException"); } catch (IOException ioe) { logger.error("Invalid JSON String IOException"); } return valid; }
Example #7
Source File: JsonSerDeser.java From hadoop with Apache License 2.0 | 6 votes |
/** * Convert from a JSON file * @param resource input file * @return the parsed JSON * @throws IOException IO problems * @throws JsonMappingException failure to map from the JSON to this class */ @SuppressWarnings({"IOResourceOpenedButNotSafelyClosed"}) public synchronized T fromResource(String resource) throws IOException, JsonParseException, JsonMappingException { InputStream resStream = null; try { resStream = this.getClass().getResourceAsStream(resource); if (resStream == null) { throw new FileNotFoundException(resource); } return mapper.readValue(resStream, classType); } catch (IOException e) { LOG.error("Exception while parsing json resource {}: {}", resource, e); throw e; } finally { IOUtils.closeStream(resStream); } }
Example #8
Source File: JsonDataValidator.java From AIDR with GNU Affero General Public License v3.0 | 6 votes |
public static boolean isValidJSON(String json) { boolean valid = false; try { final JsonParser parser = new ObjectMapper().getJsonFactory() .createJsonParser(json); while (parser.nextToken() != null) { String fieldname = parser.getCurrentName(); System.out.println("fieldname: " + fieldname); } valid = true; } catch (JsonParseException jpe) { jpe.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } return valid; }
Example #9
Source File: BasicClient.java From secure-data-service with Apache License 2.0 | 6 votes |
@Override public Response getHomeResource(Entity home) throws URISyntaxException, MessageProcessingException, IOException { URL url = URLBuilder.create(restClient.getBaseURL()).addPath(PathConstants.HOME).build(); Response response = restClient.getRequest(url); if (response.getStatus() == Response.Status.OK.getStatusCode()) { try { JsonNode element = mapper.readValue(response.readEntity(String.class), JsonNode.class); Map<String, List<Link>> links = mapper.readValue(element, new TypeReference<Map<String, List<BasicLink>>>() { }); home.getData().putAll(links); } catch (JsonParseException e) { // invalid Json, or non-Json response? ResponseBuilder builder = Response.fromResponse(response); builder.status(Response.Status.INTERNAL_SERVER_ERROR); return builder.build(); } } return response; }
Example #10
Source File: GeneralMesseageConsumer.java From laser with Apache License 2.0 | 6 votes |
private boolean setUserProfile(String uuid, Vector profile) throws JsonParseException, JsonMappingException, IOException { try { Object res = couchbaseClient.get(uuid); if (null == res) { return false; } String jsonValue = res.toString(); UserProfile userProfile = UserProfile.createUserProfile(jsonValue); userProfile.setUserFeature(profile, mapper, true); } catch (RuntimeException e) { return false; } return true; }
Example #11
Source File: JsonDataValidator.java From AIDR with GNU Affero General Public License v3.0 | 6 votes |
public static boolean isEmptySON(String json) { boolean isEmpty = true; try { final JsonParser parser = new ObjectMapper().getJsonFactory() .createJsonParser(json); while (parser.nextToken() != null) { String fieldname = parser.getCurrentName(); if(fieldname != null){ isEmpty = false; break; } } } catch (JsonParseException jpe) { System.out.println("isEmptySON: " + jpe.getMessage()); jpe.printStackTrace(); } catch (IOException ioe) { System.out.println("isEmptySON: " + ioe.getMessage()); ioe.printStackTrace(); } return isEmpty; }
Example #12
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 #13
Source File: JsonUtil.java From hbase-secondary-index with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("rawtypes") public Set<String> evaluateDistinctArray(String jsonString, String pathString) throws JsonParseException, JsonMappingException, IOException { Set<String> set = new HashSet<String>(); if (jsonString == null || jsonString == "" || pathString == null || pathString == "") { return null; } List result = MAPPER.readValue(jsonString, new TypeReference<List>() { }); for (Object o : result) { if (o instanceof LinkedHashMap) { LinkedHashMap m = (LinkedHashMap) o; set.add(m.get(pathString).toString()); } else if (o instanceof String) { String str = (String) o; String[] arr = str.split(Const.ROWKEY_DEFAULT_SEPARATOR, -1); for (String s : arr) { set.add(s); } } } return set; }
Example #14
Source File: HiveJsonStructReader.java From incubator-hivemall with Apache License 2.0 | 6 votes |
private static void skipValue(JsonParser parser) throws JsonParseException, IOException { int array = 0; int object = 0; do { JsonToken currentToken = parser.getCurrentToken(); if (currentToken == JsonToken.START_ARRAY) { array++; } if (currentToken == JsonToken.END_ARRAY) { array--; } if (currentToken == JsonToken.START_OBJECT) { object++; } if (currentToken == JsonToken.END_OBJECT) { object--; } parser.nextToken(); } while (array > 0 || object > 0); }
Example #15
Source File: AbstractJsonRowRecordReader.java From nifi with Apache License 2.0 | 5 votes |
public AbstractJsonRowRecordReader(final InputStream in, final ComponentLog logger, final String dateFormat, final String timeFormat, final String timestampFormat) throws IOException, MalformedRecordException { this.logger = logger; final DateFormat df = dateFormat == null ? null : DataTypeUtils.getDateFormat(dateFormat); final DateFormat tf = timeFormat == null ? null : DataTypeUtils.getDateFormat(timeFormat); final DateFormat tsf = timestampFormat == null ? null : DataTypeUtils.getDateFormat(timestampFormat); LAZY_DATE_FORMAT = () -> df; LAZY_TIME_FORMAT = () -> tf; LAZY_TIMESTAMP_FORMAT = () -> tsf; try { jsonParser = jsonFactory.createJsonParser(in); jsonParser.setCodec(codec); JsonToken token = jsonParser.nextToken(); if (token == JsonToken.START_ARRAY) { token = jsonParser.nextToken(); // advance to START_OBJECT token } if (token == JsonToken.START_OBJECT) { // could be END_ARRAY also firstJsonNode = jsonParser.readValueAsTree(); } else { firstJsonNode = null; } } catch (final JsonParseException e) { throw new MalformedRecordException("Could not parse data as JSON", e); } }
Example #16
Source File: HttpMetricsIngestionHandler.java From blueflood with Apache License 2.0 | 5 votes |
protected JSONMetricsContainer createContainer(String body, String tenantId) throws JsonParseException, JsonMappingException, IOException { //mapping List<JSONMetric> jsonMetrics = mapper.readValue( body, typeFactory.constructCollectionType(List.class, JSONMetric.class) ); //validation List<ErrorResponse.ErrorData> validationErrors = new ArrayList<ErrorResponse.ErrorData>(); List<JSONMetric> validJsonMetrics = new ArrayList<JSONMetric>(); for (JSONMetric metric: jsonMetrics) { Set<ConstraintViolation<JSONMetric>> constraintViolations = validator.validate(metric); if (constraintViolations.size() == 0) { validJsonMetrics.add(metric); } else { for (ConstraintViolation<JSONMetric> constraintViolation : constraintViolations) { validationErrors.add(new ErrorResponse.ErrorData(tenantId, metric.getMetricName(), constraintViolation.getPropertyPath().toString(), constraintViolation.getMessage(), metric.getCollectionTime())); } } } return new JSONMetricsContainer(tenantId, validJsonMetrics, validationErrors); }
Example #17
Source File: HttpMultitenantMetricsIngestionHandler.java From blueflood with Apache License 2.0 | 5 votes |
@Override protected JSONMetricsContainer createContainer(String body, String tenantId) throws JsonParseException, JsonMappingException, IOException { List<JSONMetric> jsonMetrics = mapper.readValue( body, typeFactory.constructCollectionType(List.class, JSONMetricScoped.class) ); //validation List<ErrorResponse.ErrorData> validationErrors = new ArrayList<ErrorResponse.ErrorData>(); List<JSONMetric> validJsonMetrics = new ArrayList<JSONMetric>(); for (JSONMetric metric: jsonMetrics) { JSONMetricScoped scopedMetric = (JSONMetricScoped) metric; Set<ConstraintViolation<JSONMetricScoped>> constraintViolations = validator.validate(scopedMetric); if (constraintViolations.size() == 0) { validJsonMetrics.add(metric); } else { for (ConstraintViolation<JSONMetricScoped> constraintViolation : constraintViolations) { validationErrors.add( new ErrorResponse.ErrorData(scopedMetric.getTenantId(), metric.getMetricName(), constraintViolation.getPropertyPath().toString(), constraintViolation.getMessage(), metric.getCollectionTime())); } } } return new JSONMetricsContainer(tenantId, validJsonMetrics, validationErrors); }
Example #18
Source File: ClusterJsonMapper.java From ensemble-clustering with MIT License | 5 votes |
public static Cluster fromJson(String jsonAsString) throws JsonMappingException, JsonParseException, IOException { mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL); Cluster cluster = mapper.readValue(jsonAsString, Cluster.class); return cluster; }
Example #19
Source File: InstanceJsonMapper.java From ensemble-clustering with MIT License | 5 votes |
public static Instance fromJson(String jsonAsString) throws JsonMappingException, JsonParseException, IOException { mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL); Instance inst = mapper.readValue(jsonAsString, Instance.class); return inst; }
Example #20
Source File: BulkImportActionExecutor.java From alfresco-bulk-import with Apache License 2.0 | 5 votes |
private final Map<String, List<String>> parseParametersJson(final String parametersJson) throws IOException, JsonMappingException, JsonParseException { Map<String, List<String>> result = null; final ObjectMapper mapper = new ObjectMapper(); final TypeReference<HashMap<String,List<String>>> typeReference = new TypeReference<HashMap<String,List<String>>>() {}; result = mapper.readValue(parametersJson, typeReference); return(result); }
Example #21
Source File: DidReferenceResolutionTest.java From secure-data-service with Apache License 2.0 | 5 votes |
@Test public void resolvesStaffRefDidInStaffEducationOrgAssignmentAssociationCorrectly() throws JsonParseException, JsonMappingException, IOException { NeutralRecordEntity entity = loadEntity("didTestEntities/staffEducationOrganizationAssociation.json"); resolveInternalId(entity); Map<String, String> naturalKeys = new HashMap<String, String>(); naturalKeys.put("staffUniqueStateId", "jjackson"); checkId(entity, "StaffReference", naturalKeys, "staff"); }
Example #22
Source File: GeoDynamoDBServlet.java From reinvent2013-mobile-photo-share with Apache License 2.0 | 5 votes |
private void printPutPointResult(PutPointResult putPointResult, PrintWriter out) throws JsonParseException, IOException { Map<String, String> jsonMap = new HashMap<String, String>(); jsonMap.put("action", "put-point"); out.println(mapper.writeValueAsString(jsonMap)); out.flush(); }
Example #23
Source File: GeoDynamoDBServlet.java From reinvent2013-mobile-photo-share with Apache License 2.0 | 5 votes |
private void printGetPointRequest(GetPointResult getPointResult, PrintWriter out) throws JsonParseException, IOException { Map<String, AttributeValue> item = getPointResult.getGetItemResult().getItem(); String geoJsonString = item.get(config.getGeoJsonAttributeName()).getS(); JsonParser jsonParser = factory.createJsonParser(geoJsonString); JsonNode jsonNode = mapper.readTree(jsonParser); double latitude = jsonNode.get("coordinates").get(0).getDoubleValue(); double longitude = jsonNode.get("coordinates").get(1).getDoubleValue(); String hashKey = item.get(config.getHashKeyAttributeName()).getN(); String rangeKey = item.get(config.getRangeKeyAttributeName()).getS(); String geohash = item.get(config.getGeohashAttributeName()).getN(); String title = item.get("title").getS(); String userId = item.get("userId").getS(); Map<String, String> resultMap = new HashMap<String, String>(); resultMap.put("latitude", Double.toString(latitude)); resultMap.put("longitude", Double.toString(longitude)); resultMap.put("hashKey", hashKey); resultMap.put("rangeKey", rangeKey); resultMap.put("geohash", geohash); resultMap.put("title", title); resultMap.put("userId", userId); Map<String, Object> jsonMap = new HashMap<String, Object>(); jsonMap.put("action", "get-point"); jsonMap.put("result", resultMap); out.println(mapper.writeValueAsString(jsonMap)); out.flush(); }
Example #24
Source File: TestBlockCreatorOperator.java From Cubert with Apache License 2.0 | 5 votes |
@Test public void testByRow() throws JsonParseException, JsonMappingException, IOException, InterruptedException { Object[][] rows = { { 3, 1 }, { 3, 2 }, { 10, 1 } }; int[] expected = { 2, 1 }; assertCreatedBlock(rows, new String[] { "a", "b" }, 1, "BY_ROW", 1, expected); assertCreatedBlock(rows, new String[] { "a", "b" }, 1, "BY_ROW", 2, expected); expected = new int[] { 2, 1 }; assertCreatedBlock(rows, new String[] { "a", "b" }, 1, "BY_ROW", 3, expected); }
Example #25
Source File: RubixBlockWriter.java From Cubert with Apache License 2.0 | 5 votes |
@Override public void configure(JsonNode json) throws JsonParseException, JsonMappingException, IOException { outputSchema = new BlockSchema(json.get("schema")); }
Example #26
Source File: JsonUtil.java From hbase-secondary-index with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("rawtypes") public List<String> evaluateArray(String jsonString, String pathString) throws JsonParseException, JsonMappingException, IOException { List<String> list = new ArrayList<String>(); if (jsonString == null || jsonString == "" || pathString == null || pathString == "") { return null; } List result = MAPPER.readValue(jsonString, new TypeReference<List>() { }); String[] arr = pathString.split(",", -1); for (Object o : result) { if (o instanceof LinkedHashMap) { LinkedHashMap m = (LinkedHashMap) o; if (arr.length == 1) list.add(m.get(pathString).toString()); else if (arr.length > 1) { StringBuilder sb = new StringBuilder(); for (String path : arr) { sb.append(m.get(path).toString() + ","); } if (sb.length() > 0) sb.setLength(sb.length() - 1); list.add(sb.toString()); } } else if (o instanceof String) { String str = (String) o; str = str.replaceAll(Const.ROWKEY_DEFAULT_SEPARATOR, ","); list.add(str); } } return list; }
Example #27
Source File: FixedJsonInstanceSerializer.java From incubator-sentry with Apache License 2.0 | 5 votes |
private <O> O getObject(final JsonNode pNode, final String pFieldName, final Class<O> pObjectClass) throws JsonParseException, JsonMappingException, IOException { Preconditions.checkNotNull(pNode); Preconditions.checkNotNull(pFieldName); Preconditions.checkNotNull(pObjectClass); if (pNode.get(pFieldName) != null && pNode.get(pFieldName).isObject()) { return mMapper.readValue(pNode.get(pFieldName), pObjectClass); } else { return null; } }
Example #28
Source File: GeoDynamoDBServlet.java From reinvent2013-mobile-photo-share with Apache License 2.0 | 5 votes |
private void printDeletePointResult(DeletePointResult deletePointResult, PrintWriter out) throws JsonParseException, IOException { Map<String, String> jsonMap = new HashMap<String, String>(); jsonMap.put("action", "delete-point"); out.println(mapper.writeValueAsString(jsonMap)); out.flush(); }
Example #29
Source File: BlockIndexJoinOperator.java From Cubert with Apache License 2.0 | 5 votes |
@Override public void setInput(Map<String, Block> input, JsonNode root, BlockProperties props) throws JsonParseException, JsonMappingException, IOException { block = input.values().iterator().next(); String[] partitionKeyColumnNames = JsonUtils.asArray(root, INPUT_PARTITION_KEY_COLUMNS); BlockSchema inputSchema = block.getProperties().getSchema(); outputTuple = TupleFactory.getInstance().newTuple(inputSchema.getNumColumns() + 1); partitionKey = TupleFactory.getInstance().newTuple(partitionKeyColumnNames.length); partitionKeyIndex = new int[partitionKeyColumnNames.length]; for (int i = 0; i < partitionKeyIndex.length; i++) partitionKeyIndex[i] = inputSchema.getIndex(partitionKeyColumnNames[i]); String indexName = JsonUtils.getText(root, "index"); try { index = FileCache.getCachedIndex(indexName); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } if (index == null) { throw new RuntimeException("Cannot load index for [" + JsonUtils.getText(root, "indexName") + "]"); } }
Example #30
Source File: AegisthusLoader.java From aegisthus with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") protected Tuple tuple(Map<String, Object> map) throws JsonParseException, IOException { List<Object> values = new ArrayList<>(); if (required(0)) { values.add(map.get(AegisthusSerializer.KEY)); } map.remove(AegisthusSerializer.KEY); if (required(1)) { values.add(map.get(AegisthusSerializer.DELETEDAT)); } map.remove(AegisthusSerializer.DELETEDAT); // Each item in the map must be a tuple if (required(2)) { Map<String, Object> map2 = Maps.newHashMap(); for (Map.Entry<String, Object> e : map.entrySet()) { map2.put(e.getKey(), tupleFactory.newTuple((List<Object>) e.getValue())); } values.add(map2); } if (required(3)) { List<Tuple> cols = Lists.newArrayList(); for (Object obj : map.values()) { cols.add(tupleFactory.newTuple((List<Object>) obj)); } values.add(bagFactory.newDefaultBag(cols)); } return tupleFactory.newTuple(values); }