Java Code Examples for org.codehaus.jackson.map.JsonMappingException
The following examples show how to use
org.codehaus.jackson.map.JsonMappingException. These examples are extracted from open source projects.
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 Project: helix Source File: MockController.java License: Apache License 2.0 | 6 votes |
void sendMessage(String msgId, String instanceName, String fromState, String toState, String partitionKey, int partitionId) throws InterruptedException, JsonGenerationException, JsonMappingException, IOException { Message message = new Message(MessageType.STATE_TRANSITION, msgId); message.setMsgId(msgId); message.setSrcName(srcName); message.setTgtName(instanceName); message.setMsgState(MessageState.NEW); message.setFromState(fromState); message.setToState(toState); // message.setPartitionId(partitionId); message.setPartitionName(partitionKey); String path = PropertyPathBuilder.instanceMessage(clusterName, instanceName, message.getId()); ObjectMapper mapper = new ObjectMapper(); StringWriter sw = new StringWriter(); mapper.writeValueUsingView(sw, message, Message.class); System.out.println(sw.toString()); client.delete(path); Thread.sleep(10000); ZNRecord record = client.readData(PropertyPathBuilder.liveInstance(clusterName, instanceName)); message.setTgtSessionId(record.getSimpleField(LiveInstanceProperty.SESSION_ID.toString()) .toString()); client.createPersistent(path, message); }
Example 2
Source Project: demo-restWS-spring-jersey-jpa2-hibernate Source File: RestDemoServiceIT.java License: MIT License | 6 votes |
@Test public void testGetLegacyPodcast() throws JsonGenerationException, JsonMappingException, IOException { ClientConfig clientConfig = new ClientConfig(); clientConfig.register(JacksonFeature.class); Client client = ClientBuilder.newClient(clientConfig); WebTarget webTarget = client .target("http://localhost:8888/demo-rest-spring-jersey-jpa2-hibernate-0.0.1-SNAPSHOT/podcasts/2"); Builder request = webTarget.request(MediaType.APPLICATION_JSON); Response response = request.get(); Assert.assertTrue(response.getStatus() == 200); Podcast podcast = response.readEntity(Podcast.class); ObjectMapper mapper = new ObjectMapper(); System.out .print("Received podcast from database *************************** " + mapper.writerWithDefaultPrettyPrinter() .writeValueAsString(podcast)); }
Example 3
Source Project: hadoop Source File: JsonSerDeser.java License: 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 4
Source Project: FoxBPM Source File: FoxbpmStatusService.java License: Apache License 2.0 | 6 votes |
public Status getStatus(Throwable throwable, Request request, Response response) { Status status = null; if (throwable instanceof JsonMappingException && throwable.getCause() != null) { status = getSpecificStatus(throwable.getCause(), request, response); } if (status == null) { Throwable causeThrowable = null; if (throwable.getCause() != null && throwable.getCause() instanceof FoxBPMException) { causeThrowable = throwable.getCause(); } else { causeThrowable = throwable; } status = getSpecificStatus(causeThrowable, request, response); } return status != null ? status : Status.SERVER_ERROR_INTERNAL; }
Example 5
Source Project: big-c Source File: JsonSerDeser.java License: 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 6
Source Project: laser Source File: GeneralMesseageConsumer.java License: 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 7
Source Project: tac2015-event-detection Source File: SocketServer.java License: GNU General Public License v3.0 | 6 votes |
/*********** stdin/namedpipe loop ***********/ void namedpipeLoop() throws JsonGenerationException, JsonMappingException, IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in, "UTF-8")); String inputline; BufferedOutputStream out = new BufferedOutputStream( new FileOutputStream(outpipeFilename, true)); // OutputStream out = new FileOutputStream(outpipeFilename, true); log("Waiting for commands on stdin"); while ( (inputline=reader.readLine()) != null) { JsonNode result = parseAndRunCommand(inputline); writeResultToStream(result, out); out.flush(); checkTimings(); } }
Example 8
Source Project: helix Source File: CurrentStateResource.java License: Apache License 2.0 | 6 votes |
StringRepresentation getInstanceCurrentStateRepresentation(String clusterName, String instanceName, String resourceGroup) throws JsonGenerationException, JsonMappingException, IOException { ZkClient zkClient = (ZkClient) getRequest().getAttributes().get(RestAdminApplication.ZKCLIENT); String instanceSessionId = ClusterRepresentationUtil.getInstanceSessionId(zkClient, clusterName, instanceName); Builder keyBuilder = new PropertyKey.Builder(clusterName); String message = ClusterRepresentationUtil.getInstancePropertyAsString(zkClient, clusterName, keyBuilder.currentState(instanceName, instanceSessionId, resourceGroup), MediaType.APPLICATION_JSON); StringRepresentation representation = new StringRepresentation(message, MediaType.APPLICATION_JSON); return representation; }
Example 9
Source Project: incubator-pinot Source File: DelegatingAvroKeyInputFormat.java License: 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 10
Source Project: realtime-analytics Source File: Simulator.java License: GNU General Public License v2.0 | 6 votes |
private static void sendMessage() throws IOException, JsonProcessingException, JsonGenerationException, JsonMappingException, UnsupportedEncodingException, HttpException { ObjectMapper mapper = new ObjectMapper(); Map<String, Object> m = new HashMap<String, Object>(); m.put("si", "12345"); m.put("ct", System.currentTimeMillis()); String payload = mapper.writeValueAsString(m); HttpClient client = new HttpClient(); PostMethod method = new PostMethod("http://localhost:8080/tracking/ingest/PulsarRawEvent"); // method.addRequestHeader("Accept-Encoding", "gzip,deflate,sdch"); method.setRequestEntity(new StringRequestEntity(payload, "application/json", "UTF-8")); int status = client.executeMethod(method); System.out.println(Arrays.toString(method.getResponseHeaders())); System.out.println("Status code: " + status + ", Body: " + method.getResponseBodyAsString()); }
Example 11
Source Project: SI Source File: OpenApiService.java License: BSD 2-Clause "Simplified" License | 6 votes |
public HashMap<String, Object> execute(String operation, String content) throws JsonGenerationException, JsonMappingException, IOException, UserSysException { HashMap<String, Object> res = callOpenAPI(operation, content); //try { //int status = (Integer)res.get("status"); String body = (String)res.get("body"); ObjectMapper mapper = new ObjectMapper(); Object json = mapper.readValue(body, Object.class); res.put("json", json); //} catch (JsonGenerationException ex) { // res.put("exception", ex); //} catch (JsonMappingException ex) { // res.put("exception", ex); //} catch (IOException ex) { // res.put("exception", ex); //} catch (UserSysException ex) { //} return res; }
Example 12
Source Project: torrenttunes-client Source File: DerpTest.java License: GNU General Public License v3.0 | 6 votes |
public void derp() throws JsonGenerationException, JsonMappingException, IOException { // TorrentClient tc = TorrentClient.start(); // ScanDirectory.start(new File(DataSources.SAMPLE_MUSIC_DIR), tc); // List all the music files in the sub or sub directories // String[] types = {"mp3"}; // // Collection<File> files = FileUtils.listFiles(new File(DataSources.SAMPLE_MUSIC_DIR), types , true); // // // Set<ScanInfo> scanInfos = new LinkedHashSet<ScanInfo>(); // // for (File file : files) { // scanInfos.add(ScanInfo.create(file)); // } // // String json = Tools.MAPPER.writeValueAsString(scanInfos); // System.out.println(json); Song song = Song.fetchSong(new File("/home/tyler/.torrenttunes-client/cache/1-06 Raconte-Moi Une Histoire.mp3")); System.out.println(song.getRecording()); }
Example 13
Source Project: torrenttunes-client Source File: DerpTest.java License: GNU General Public License v3.0 | 6 votes |
public static void derp6() throws JsonGenerationException, JsonMappingException, IOException { // Song song = Song.fetchSong(new File(DataSources.SAMPLE_SONG)); // // String songJson = Tools.MAPPER.writeValueAsString(song); // // // Add the mac_address // ObjectNode on = Tools.MAPPER.valueToTree(Tools.jsonToNode(songJson)); // on.put("uploader_ip_hash", DataSources.IP_HASH); // // String songUploadJson = Tools.nodeToJson(on); // log.info("song upload json:\n" + songUploadJson); // System.out.println(Tools.GSON2.toJson(Strings.EN.map)); // Map<String, String> map = Strings.EN.map; // // for (Entry<String, String> e : map.entrySet()) { // System.out.println(e.getKey() + " : " + e.getValue()); // } // WriteMultilingualHTMLFiles.write(); }
Example 14
Source Project: helix Source File: CurrentStatesResource.java License: Apache License 2.0 | 6 votes |
StringRepresentation getInstanceCurrentStatesRepresentation(String clusterName, String instanceName) throws JsonGenerationException, JsonMappingException, IOException { ZkClient zkClient = (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT); ; String instanceSessionId = ClusterRepresentationUtil.getInstanceSessionId(zkClient, clusterName, instanceName); String message = ClusterRepresentationUtil .getInstancePropertyNameListAsString(zkClient, clusterName, instanceName, PropertyType.CURRENTSTATES, instanceSessionId, MediaType.APPLICATION_JSON); StringRepresentation representation = new StringRepresentation(message, MediaType.APPLICATION_JSON); return representation; }
Example 15
Source Project: Cubert Source File: TestOLAPCubeCountDistinct.java License: Apache License 2.0 | 6 votes |
@Test void testThreeDimsTeam() throws JsonGenerationException, JsonMappingException, IOException, InterruptedException { Object[][] rows = { { 1, (int) 1, (int) 2, (int) 1 }, { 2, (int) 1, (int) 2, (int) 2 }, { 3, (int) 1, (int) 1, (int) 1 }, { 4, (int) 1, (int) 1, (int) 2 }, { 5, (int) 2, (int) 2, (int) 2 } }; String[] expected = new String[] { "(1,2,1,1)", "(1,2,2,1)", "(1,1,1,1)", "(1,1,2,1)", "(2,2,2,1)", "(1,,,4)", "(2,,,1)", "(,1,,2)", "(,2,,3)", "(,,1,2)", "(,,2,3)", "(1,1,,2)", "(1,2,,2)", "(2,2,,1)", "(,1,1,1)", "(,1,2,1)", "(,2,1,1)", "(,2,2,2)", "(1,,1,2)", "(1,,2,2)", "(2,,2,1)", "(,,,5)" }; validate(rows, expected); }
Example 16
Source Project: Cubert Source File: TestOLAPCubeCountDistinct.java License: Apache License 2.0 | 6 votes |
@Test void testThreeDimsTeamGroupingSets() throws JsonGenerationException, JsonMappingException, IOException, InterruptedException { // members: srinivas, maneesh, krishna, saurabh, rui // dimensions: country code, number of monitors, vegetarian Object[][] rows = { { 1, (int) 1, (int) 2, (int) 1 }, { 2, (int) 1, (int) 2, (int) 2 }, { 3, (int) 1, (int) 1, (int) 1 }, { 4, (int) 1, (int) 1, (int) 2 }, { 5, (int) 2, (int) 2, (int) 2 } }; String[] expected = new String[] { "(1,,,4)", "(2,,,1)", "(1,1,,2)", "(1,2,,2)", "(2,2,,1)" }; validateGroupingSets(rows, expected, new String[] { "Dim0,Dim1", "Dim0" }); }
Example 17
Source Project: Cubert Source File: TestOLAPCube.java License: Apache License 2.0 | 6 votes |
@Test void testGroupingSetsSum() throws JsonGenerationException, JsonMappingException, IOException, InterruptedException { // clickCount // dimensions: country code, number of monitors, vegetarian Object[][] rows = { { 1, (int) 1, (int) 1, (int) 1 }, { 1, (int) 1, (int) 1, (int) 2 }, { 2, (int) 1, (int) 2, (int) 1 }, { 3, (int) 1, (int) 2, (int) 2 }, { 2, (int) 2, (int) 2, (int) 2 } }; String[] expected = new String[] { "(1,,,7)", "(2,,,2)", "(1,1,,2)", "(1,2,,5)", "(2,2,,2)" }; validateGroupingSets(rows, expected, new String[] { "Dim0,Dim1", "Dim0" }); }
Example 18
Source Project: incubator-pinot Source File: DelegatingAvroKeyInputFormat.java License: 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 19
Source Project: Bats Source File: PubSubWebSocketClient.java License: Apache License 2.0 | 5 votes |
@Override public void onMessage(String message) { PubSubMessage<Object> pubSubMessage; try { pubSubMessage = codec.parseMessage(message); PubSubWebSocketClient.this.onMessage(pubSubMessage.getType().getIdentifier(), pubSubMessage.getTopic(), pubSubMessage.getData()); } catch (JsonParseException jpe) { logger.warn("Ignoring unparseable JSON message: {}", message, jpe); } catch (JsonMappingException jme) { logger.warn("Ignoring JSON mapping in message: {}", message, jme); } catch (IOException ex) { onError(ex); } }
Example 20
Source Project: Cubert Source File: TestBlock.java License: Apache License 2.0 | 5 votes |
@Test public void testReadEmptyBlock() throws JsonGenerationException, JsonMappingException, IOException, InterruptedException { Object[][] rows = {}; Block block = new ArrayBlock(Arrays.asList(rows), new String[] { "A" }); assert block.next() == null; }
Example 21
Source Project: localization_nifi Source File: JsonMappingExceptionMapper.java License: Apache License 2.0 | 5 votes |
@Override public Response toResponse(JsonMappingException ex) { // log the error logger.info(String.format("%s. Returning %s response.", ex, Response.Status.BAD_REQUEST)); if (logger.isDebugEnabled()) { logger.debug(StringUtils.EMPTY, ex); } return Response.status(Response.Status.BAD_REQUEST).entity("Message body is malformed. Unable to map into expected format.").type("text/plain").build(); }
Example 22
Source Project: boubei-tss Source File: ImportReport.java License: Apache License 2.0 | 5 votes |
public int createReports(String json, String dataSource, Long groupId) throws IOException, JsonParseException, JsonMappingException { int count = 0; Map<Long, Long> idMapping = new HashMap<Long, Long>(); List<?> list = new ObjectMapper().readValue(json, List.class); for (int i = 0; i < list.size(); i++) { Object obj = list.get(i); // Map Report report = new ObjectMapper().readValue(EasyUtils.obj2Json(obj), Report.class); Long oldId = report.getId(); report.setId(null); if ( i == 0 ) { report.setParentId(groupId); } else { report.setParentId(idMapping.get(report.getParentId())); } if( !report.isGroup() ) { count ++; report.setDatasource(dataSource); } Integer status = report.getDisabled(); reportService.createReport(report); report.setDisabled(status); // 因默认创建分组都是停用状态,但导入分组不需要,保留原来状态 reportService.updateReport(report); idMapping.put(oldId, report.getId()); } return count; }
Example 23
Source Project: openmrs-module-initializer Source File: Utils.java License: MIT License | 5 votes |
/** * Convenience method to serialize a JSON object that also handles the simple string case. */ public static String asString(Object jsonObj) throws JsonGenerationException, JsonMappingException, IOException { if (jsonObj == null) { return ""; } if (jsonObj instanceof String) { return (String) jsonObj; } else { return (new ObjectMapper()).writeValueAsString(jsonObj); } }
Example 24
Source Project: openmrs-module-initializer Source File: Utils.java License: MIT License | 5 votes |
/** * Convenience method to read a list of string out of a JSON string. */ public static List<String> asStringList(String jsonString) throws JsonParseException, JsonMappingException, IOException { List<Object> list = (new ObjectMapper()).readValue(jsonString, List.class); List<String> stringList = new ArrayList<String>(); for (Object o : list) { stringList.add(asString(o)); } return stringList; }
Example 25
Source Project: helix Source File: ClusterRepresentationUtil.java License: Apache License 2.0 | 5 votes |
public static String ObjectToJson(Object object) throws JsonGenerationException, JsonMappingException, IOException { ObjectMapper mapper = new ObjectMapper(); SerializationConfig serializationConfig = mapper.getSerializationConfig(); serializationConfig.set(SerializationConfig.Feature.INDENT_OUTPUT, true); StringWriter sw = new StringWriter(); mapper.writeValue(sw, object); return sw.toString(); }
Example 26
Source Project: hadoop Source File: JsonSerDeser.java License: Apache License 2.0 | 5 votes |
/** * Convert from JSON * * @param json input * @return the parsed JSON * @throws IOException IO * @throws JsonMappingException failure to map from the JSON to this class */ @SuppressWarnings("unchecked") public synchronized T fromJson(String json) throws IOException, JsonParseException, JsonMappingException { try { return mapper.readValue(json, classType); } catch (IOException e) { LOG.error("Exception while parsing json : " + e + "\n" + json, e); throw e; } }
Example 27
Source Project: ureport Source File: DatasourceServletAction.java License: Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private Map<String, Object> buildParameters(String parameters) throws IOException, JsonParseException, JsonMappingException { Map<String,Object> map=new HashMap<String,Object>(); if(StringUtils.isBlank(parameters)){ return map; } ObjectMapper mapper=new ObjectMapper(); List<Map<String,Object>> list=mapper.readValue(parameters, ArrayList.class); for(Map<String,Object> param:list){ String name=param.get("name").toString(); DataType type=DataType.valueOf(param.get("type").toString()); String defaultValue=(String)param.get("defaultValue"); if(defaultValue==null || defaultValue.equals("")){ switch(type){ case Boolean: map.put(name, false); case Date: map.put(name, new Date()); case Float: map.put(name, new Float(0)); case Integer: map.put(name, 0); case String: if(defaultValue!=null && defaultValue.equals("")){ map.put(name, ""); }else{ map.put(name, "null"); } break; case List: map.put(name, new ArrayList<Object>()); } }else{ map.put(name, type.parse(defaultValue)); } } return map; }
Example 28
Source Project: big-c Source File: JsonSerDeser.java License: Apache License 2.0 | 5 votes |
/** * Convert from JSON * * @param json input * @return the parsed JSON * @throws IOException IO * @throws JsonMappingException failure to map from the JSON to this class */ @SuppressWarnings("unchecked") public synchronized T fromJson(String json) throws IOException, JsonParseException, JsonMappingException { try { return mapper.readValue(json, classType); } catch (IOException e) { LOG.error("Exception while parsing json : " + e + "\n" + json, e); throw e; } }
Example 29
Source Project: big-c Source File: JsonSerDeser.java License: Apache License 2.0 | 5 votes |
/** * Load from a Hadoop filesystem * @param fs filesystem * @param path path * @return a loaded CD * @throws IOException IO problems * @throws EOFException if not enough bytes were read in * @throws JsonParseException parse problems * @throws JsonMappingException O/J mapping problems */ public T load(FileSystem fs, Path path) throws IOException, JsonParseException, JsonMappingException { FileStatus status = fs.getFileStatus(path); long len = status.getLen(); byte[] b = new byte[(int) len]; FSDataInputStream dataInputStream = fs.open(path); int count = dataInputStream.read(b); if (count != len) { throw new EOFException(path.toString() + ": read finished prematurely"); } return fromBytes(path.toString(), b); }
Example 30
Source Project: Cubert Source File: TestOperators.java License: Apache License 2.0 | 5 votes |
@Test // when there are multiple rows in one table public void testHashJoin2() throws JsonGenerationException, JsonMappingException, IOException, InterruptedException { Object[][] rows1 = { { 2 }, { 2 }, { 5 }, { 10 } }; Object[][] rows2 = { { 1 }, { 7 }, { 9 } }; Object[][] expected = {}; Block block1 = new ArrayBlock(Arrays.asList(rows1), new String[] { "a" }); Block block2 = new ArrayBlock(Arrays.asList(rows2), new String[] { "a" }); TupleOperator operator = new HashJoinOperator(); Map<String, Block> input = new HashMap<String, Block>(); input.put("block1", block1); input.put("block2", block2); ObjectMapper mapper = new ObjectMapper(); ObjectNode node = mapper.createObjectNode(); node.put("leftJoinKeys", "a"); node.put("rightJoinKeys", "a"); node.put("leftBlock", "block1"); BlockProperties props = new BlockProperties(null, new BlockSchema("INT block1___a, INT block2___a"), (BlockProperties) null); operator.setInput(input, node, props); Block output = new TupleOperatorBlock(operator, props); ArrayBlock.assertData(output, expected, new String[] { "block1.a", "block2.a" }); }