当前位置: 首页>>代码示例>>Java>>正文


Java ObjectMapper.readValue方法代码示例

本文整理汇总了Java中org.codehaus.jackson.map.ObjectMapper.readValue方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectMapper.readValue方法的具体用法?Java ObjectMapper.readValue怎么用?Java ObjectMapper.readValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.codehaus.jackson.map.ObjectMapper的用法示例。


在下文中一共展示了ObjectMapper.readValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testDeserializeJsonCreateJvm

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
@Test
public void testDeserializeJsonCreateJvm() throws Exception {
    final InputStream in = this.getClass().getResourceAsStream("/json-create-jvm-data.json");
    final String jsonData = IOUtils.toString(in, Charset.defaultCharset());

    final ObjectMapper mapper = new ObjectMapper();

    final JsonCreateJvm jsonCreateJvm = mapper.readValue(jsonData, JsonCreateJvm.class);
    assertEquals("my-jvm", jsonCreateJvm.getJvmName());
    assertEquals("some-host", jsonCreateJvm.getHostName());
    assertEquals("jwala", jsonCreateJvm.getUserName());
    assertEquals("/manager", jsonCreateJvm.getStatusPath());
    assertEquals("1", jsonCreateJvm.getJdkMediaId());
    assertTrue(StringUtils.isNotEmpty(jsonCreateJvm.getEncryptedPassword()));
    assertNotEquals("password", jsonCreateJvm.getEncryptedPassword());
    assertEquals("8893", jsonCreateJvm.getAjpPort());
    assertEquals("8889", jsonCreateJvm.getHttpPort());
    assertEquals("8890", jsonCreateJvm.getHttpsPort());
    assertEquals("8891", jsonCreateJvm.getRedirectPort());
    assertEquals("8892", jsonCreateJvm.getShutdownPort());
    assertEquals("1", jsonCreateJvm.getGroupIds().get(0).getGroupId());
}
 
开发者ID:cerner,项目名称:jwala,代码行数:23,代码来源:JsonCreateJvmDeserializerTest.java

示例2: parseResponse

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
@Override
public PollTopicResult parseResponse(HttpResponse response, ObjectMapper mapper) throws IOException, PyroclastAPIException {
    int status = response.getStatusLine().getStatusCode();

    switch (status) {
        case 200:
            HttpEntity entity = response.getEntity();
            StringWriter writer = new StringWriter();
            IOUtils.copy(entity.getContent(), writer, "UTF-8");
            String json = writer.toString();

            return mapper.readValue(json, PollTopicResult.class);

        case 401:
            throw new UnauthorizedAccessException();

        default:
            throw new UnknownAPIException(response.getStatusLine().toString());
    }
}
 
开发者ID:PyroclastIO,项目名称:pyroclast-java,代码行数:21,代码来源:PollTopicParser.java

示例3: deserialize

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
@Override
public StatePair deserialize(JsonParser parser, 
                             DeserializationContext context)
throws IOException, JsonProcessingException {
  ObjectMapper mapper = (ObjectMapper) parser.getCodec();
  // set the state-pair object tree
  ObjectNode statePairObject = (ObjectNode) mapper.readTree(parser);
  Class<?> stateClass = null;
  
  try {
    stateClass = 
      Class.forName(statePairObject.get("className").getTextValue().trim());
  } catch (ClassNotFoundException cnfe) {
    throw new RuntimeException("Invalid classname!", cnfe);
  }
  
  String stateJsonString = statePairObject.get("state").toString();
  State state = (State) mapper.readValue(stateJsonString, stateClass);
  
  return new StatePair(state);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:22,代码来源:StateDeserializer.java

示例4: getApplications

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
public static List<Application> getApplications( String response )
{
    List<Application> applications = new ArrayList<>();
    ObjectMapper mapper = new ObjectMapper();
    try
    {
        applications = mapper.readValue( response, new TypeReference<List<Application>>()
        {
        } );
    }
    catch ( IOException e )
    {
        e.printStackTrace();
    }
    return applications;
}
 
开发者ID:oncecloud,项目名称:devops-cstack,代码行数:17,代码来源:JsonConverter.java

示例5: createNewUser

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
@Override
public boolean createNewUser(String u, String p) {
	HttpHeaders headers = new HttpHeaders();
   	headers.setContentType(MediaType.APPLICATION_JSON);
	ObjectMapper mapper=ObjectMapperPool.getMapper();

	String json="";
	try {
		json = mapper.writeValueAsString(new LoginRequest(u, p, fingerPrint.getFingerPrint()));
	
		HttpEntity<String> entity = new HttpEntity<String>(json, headers);
		ResponseEntity<String> response=restTemplate.postForEntity(serverPath.concat(Constants.CREATE_USER_SUFFIX), entity, String.class);
		CreateUserResponse resp=mapper.readValue(response.getBody(), CreateUserResponse.class);
		logger.debug("Got create user response {}",resp.getStatus());
		return resp.isResult();
	} catch (Exception e) {
		logger.error("Parse exception", e);
	}
	return false;
}
 
开发者ID:zafar142007,项目名称:FolderSync,代码行数:21,代码来源:Auth.java

示例6: JsonFactory

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
/**
 * manifest_jsonのschema値がURL形式でない場合falseが返却されること.
 * @throws IOException IOException
 */
@SuppressWarnings("unchecked")
@Test
public void manifest_jsonのschema値がURL形式でない場合falseが返却されること() throws IOException {
    JsonFactory f = new JsonFactory();
    JSONObject json = new JSONObject();
    json.put("bar_version", "1");
    json.put("box_version", "1");
    json.put("DefaultPath", "boxName");
    json.put("schema", "test");
    JsonParser jp = f.createJsonParser(json.toJSONString());
    ObjectMapper mapper = new ObjectMapper();
    jp.nextToken();

    JSONManifest manifest = mapper.readValue(jp, JSONManifest.class);

    assertFalse(manifest.checkSchema());
}
 
开发者ID:personium,项目名称:personium-core,代码行数:22,代码来源:JSONManifestTest.java

示例7: getMessage

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
public static List<Message> getMessage( String response )
{
    ObjectMapper mapper = new ObjectMapper();
    List<Message> messages = null;
    try
    {
        messages = mapper.readValue( response, new TypeReference<List<Message>>()
        {
        } );
    }
    catch ( IOException e )
    {
        e.printStackTrace();
    }
    return messages;
}
 
开发者ID:oncecloud,项目名称:devops-cstack,代码行数:17,代码来源:JsonConverter.java

示例8: getProperty

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
/**
 * In order to query a namenode mxbean, a http connection in the form of
 * "http://hostname/jmx?qry=Hadoop:service=NameNode,name=NameNodeInfo"
 * is sent to namenode.  JMX attributes are exposed via JmxJsonServelet on 
 * the namenode side.
 */
private static JsonNode getProperty(String props, String propertyname)
throws IOException {
  if (props == null || props.equals("") || propertyname == null 
      || propertyname.equals("")) {
    return null;
  }
  ObjectMapper m = new ObjectMapper();
  JsonNode rootNode = m.readValue(props, JsonNode.class);
  JsonNode jn = rootNode.get("beans").get(0).get(propertyname);
  return jn;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:18,代码来源:ClusterJspHelper.java

示例9: testSerialization

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
@Test
public void testSerialization()
throws JsonGenerationException, JsonMappingException, IOException {
  PerformanceEvaluation.TestOptions options = new PerformanceEvaluation.TestOptions();
  assertTrue(!options.isAutoFlush());
  options.setAutoFlush(true);
  ObjectMapper mapper = new ObjectMapper();
  String optionsString = mapper.writeValueAsString(options);
  PerformanceEvaluation.TestOptions optionsDeserialized =
      mapper.readValue(optionsString, PerformanceEvaluation.TestOptions.class);
  assertTrue(optionsDeserialized.isAutoFlush());
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:13,代码来源:TestPerformanceEvaluation.java

示例10: readFrom

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
@Override
public Map readFrom(Class<Map> type, Type genericType,
    Annotation[] annotations, MediaType mediaType,
    MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
    throws IOException, WebApplicationException {
  ObjectMapper mapper = new ObjectMapper();
  return mapper.readValue(entityStream, type);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:9,代码来源:KMSJSONReader.java

示例11: json2Bean

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
/**
 * 输入和输出都有可能为null, 注意null检查
 */
public static <E> E json2Bean(ObjectMapper m, String json, Class<E> type) {

    try {
        return m.readValue(json, type);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:jiumao-org,项目名称:wechat-mall,代码行数:13,代码来源:JsonUtil.java

示例12: getImage

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
public static Image getImage(String response )
{
    Image image = new Image();
    ObjectMapper mapper = new ObjectMapper();
    try
    {
        image = mapper.readValue( response, Image.class );
    }
    catch ( IOException e )
    {
        e.printStackTrace();
    }
    return image;
}
 
开发者ID:oncecloud,项目名称:devops-cstack,代码行数:15,代码来源:JsonConverter.java

示例13: deserialize

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
@Override
public PollTopicResult deserialize(JsonParser jp, DeserializationContext dc) throws IOException, JsonProcessingException {
    ObjectMapper mapper = new ObjectMapper();
    JsonNode node = jp.getCodec().readTree(jp);
    List<TopicRecord> records = new ArrayList<>();

    Iterator<JsonNode> it = node.iterator();
    while (it.hasNext()) {
        JsonNode n = it.next();
        TopicRecord tr = mapper.readValue(n.toString(), TopicRecord.class);
        records.add(tr);
    }

    return new PollTopicResult(true, records);
}
 
开发者ID:PyroclastIO,项目名称:pyroclast-java,代码行数:16,代码来源:PollTopicResponseDeserializer.java

示例14: checkValueJSON

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
protected static void checkValueJSON(String table, String row, String column,
    String value) throws IOException, JAXBException {
  Response response = getValueJson(table, row, column);
  assertEquals(response.getCode(), 200);
  assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
  ObjectMapper mapper = new JacksonProvider()
  .locateMapper(CellSetModel.class, MediaType.APPLICATION_JSON_TYPE);
  CellSetModel cellSet = mapper.readValue(response.getBody(), CellSetModel.class);
  RowModel rowModel = cellSet.getRows().get(0);
  CellModel cell = rowModel.getCells().get(0);
  assertEquals(Bytes.toString(cell.getColumn()), column);
  assertEquals(Bytes.toString(cell.getValue()), value);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:14,代码来源:RowResourceBase.java

示例15: getBlockNr

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
public long getBlockNr(String tx) throws IOException {
    String s = "https://" + url + "/api/v1/tx/info/" + tx;

    HttpHeaders headers = new HttpHeaders();
    headers.set("User-Agent", options.getUserAgent());

    ResponseEntity<String> res = restTemplate.exchange(s, HttpMethod.GET, new HttpEntity<>(null, headers), String.class);
    ObjectMapper objectMapper = new ObjectMapper();
    TxInfoReturnValue retVal = objectMapper.readValue(res.getBody(), TxInfoReturnValue.class);

    return retVal.data.block;
}
 
开发者ID:modum-io,项目名称:tokenapp-backend,代码行数:13,代码来源:Blockr.java


注:本文中的org.codehaus.jackson.map.ObjectMapper.readValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。