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


Java ObjectMapper.convertValue方法代码示例

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


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

示例1: jsonListSerialization

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
/**
 * Serialize a list of objects with all the class attributes 
 * @param objects
 * @return
 * @throws Exception 
 */
public static JsonNode jsonListSerialization(List<Person> objects) throws Exception
{
    ObjectMapper mapper = new ObjectMapper();
    DateFormat myDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
    mapper.setDateFormat(myDateFormat); 
    return mapper.convertValue(objects, JsonNode.class);
}
 
开发者ID:ejesposito,项目名称:CS6310O01,代码行数:14,代码来源:Person.java

示例2: jsonListSerialization

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
/**
 * Serialize a list of objects with all the class attributes 
 * @param objects
 * @return
 * @throws Exception 
 */
public static JsonNode jsonListSerialization(List<Record> objects) throws Exception
{
    ObjectMapper mapper = new ObjectMapper();
    DateFormat myDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
    mapper.setDateFormat(myDateFormat); 
    return mapper.convertValue(objects, JsonNode.class);
}
 
开发者ID:ejesposito,项目名称:CS6310O01,代码行数:14,代码来源:Record.java

示例3: setDatasetRecord

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public static void setDatasetRecord (JsonNode dataset) throws Exception {
  ObjectMapper om = new ObjectMapper();
  om.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
  DatasetRecord record = om.convertValue(dataset, DatasetRecord.class);

  if (record != null) {
    Map<String, Object> params = new HashMap<>();
    params.put("urn", record.getUrn());
    if (record.getUrn().indexOf(":///") == -1) {
      throw new Exception("improperly formatted urn: " + record.getUrn() + ", requires ':///'");
    }
    try {
      Map<String, Object> result = JdbcUtil.wherehowsNamedJdbcTemplate.queryForMap(GET_DATASET_BY_URN, params);
      updateDataset(dataset);
    } catch (EmptyResultDataAccessException e) {
      insertDataset(dataset);
    }
  }
}
 
开发者ID:SirAeroWN,项目名称:premier-wherehows,代码行数:20,代码来源:DatasetDao.java

示例4: updateDataset

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public static void updateDataset(JsonNode dataset)
  throws Exception {
  ObjectMapper om = new ObjectMapper();
  om.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
  DatasetRecord record = om.convertValue(dataset, DatasetRecord.class);
  if (record.getRefDatasetUrn() != null) {
    Map<String, Object> refDataset = getDatasetByUrn(record.getRefDatasetUrn());
    // Find ref dataset id
    if (refDataset != null) {
      record.setRefDatasetId(((Long) refDataset.get("id")).intValue());
    }
  }

  DatabaseWriter dw = new DatabaseWriter(JdbcUtil.wherehowsJdbcTemplate, "dict_dataset");
  dw.update(record.toUpdateDatabaseValue(), record.getUrn());
  dw.close();
}
 
开发者ID:SirAeroWN,项目名称:premier-wherehows,代码行数:18,代码来源:DatasetDao.java

示例5: testReadPath

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public static void testReadPath() throws JsonProcessingException, IOException {
	String data = "{"
			+ "\"post\": { \"tags\": [\"pet\"], \"summary\": \"add a new pet to the store\", \"description\": \"\", \"operationid\": \"addpet\", \"consumes\": [\"application/json\", \"application/xml\"], \"produces\": [\"application/xml\", \"application/json\"], \"parameters\": [{ \"in\": \"body\", \"name\": \"body\", \"description\": \"pet object that needs to be added to the store\", \"required\": true, \"schema\": { \"$ref\": \"#/definitions/pet\" } }], \"responses\": { \"405\": { \"description\": \"invalid input\" } }, \"security\": [{ \"petstore_auth\": [\"write:pets\", \"read:pets\"] }] },"
			+ "\"put\": { \"tags\": [\"pet\"], \"summary\": \"update an existing pet\", \"description\": \"\", \"operationid\": \"updatepet\", \"consumes\": [\"application/json\", \"application/xml\"], \"produces\": [\"application/xml\", \"application/json\"], \"parameters\": [{ \"in\": \"body\", \"name\": \"body\", \"description\": \"pet object that needs to be added to the store\", \"required\": true, \"schema\": { \"$ref\": \"#/definitions/pet\" } }], \"responses\": { \"400\": { \"description\": \"invalid id supplied\" }, \"404\": { \"description\": \"pet not found\" }, \"405\": { \"description\": \"validation exception\" } }, \"security\": [{ \"petstore_auth\": [\"write:pets\", \"read:pets\"] }] }"
			+ "}";
	ObjectMapper mapper = Json.mapper();
	JsonNode pathNode = mapper.readTree(data);
	Path path = mapper.convertValue(pathNode, Path.class);
	Json.prettyPrint(path);
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:11,代码来源:SwaggerUtils.java

示例6: asDocumentInternal

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Override
public <T> Document asDocumentInternal(T object) {
    ObjectMapper objectMapper = getObjectMapper();
    try {
        JsonNode node = objectMapper.convertValue(object, JsonNode.class);
        return loadDocument(node);
    } catch (IllegalArgumentException iae) {
        log.error("Error while converting object to document ", iae);
        if (iae.getCause() instanceof JsonMappingException) {
            JsonMappingException jme = (JsonMappingException) iae.getCause();
            if (jme.getCause() instanceof StackOverflowError) {
                throw new ObjectMappingException(errorMessage(
                        "cyclic reference detected. " + jme.getPathReference(), OME_CYCLE_DETECTED));
            }
        }
        throw iae;
    }
}
 
开发者ID:dizitart,项目名称:nitrite-database,代码行数:19,代码来源:JacksonMapper.java

示例7: updateProperties

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public static void updateProperties(JsonNode propChanges) throws Exception, SQLException, IOException {
  String urn = propChanges.get("urn").textValue();
  Map<String, Object> row = null;
  Logger.info("urn: " + urn);
  Map<String, Object> params = new HashMap<>();
  params.put("urn", urn);
  List<Map<String, Object>> rows = JdbcUtil.wherehowsNamedJdbcTemplate.queryForList("SELECT * FROM dict_dataset WHERE urn=:urn", params);
  if (rows.size() > 0) {
    row = rows.get(0);
    Logger.info("row: " + row.toString());
    String oldProps = (String) row.get("properties");
    String youngProps = propChanges.toString();
    String updateProps = editProps(oldProps, youngProps);
    Logger.info("updateProps: " + updateProps);
    row.put("properties", updateProps);
    // need to remove these properties because they don't like being updated
    row.remove("created_time");
    row.remove("modified_time");
    row.remove("wh_etl_exec_id");
    ObjectMapper mapper = new ObjectMapper();
    JsonNode temp = mapper.convertValue(row, JsonNode.class);
    updateDataset(temp);
  } else {
    Logger.debug("nothing found for urn: " + urn);
    throw new Exception("nothing found for urn: " + urn);
  }
}
 
开发者ID:SirAeroWN,项目名称:premier-wherehows,代码行数:28,代码来源:DatasetDao.java

示例8: EntityToNameValueList

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
/**
 * Formats and return selected fields.
 *
 * @param entity Java object to update.
 * @param selectFields Selected fields.
 * @return Formatted selected fields.
 */
private static Map<String, Object> EntityToNameValueList(Object entity, List<String> selectFields) {
    if (entity == null) {
        return null;
    }

    ObjectMapper mapper = JsonObjectMapper.getMapper();
    Map<String, Object> tempEntity = mapper.convertValue(entity, Map.class);

    if (tempEntity == null) {
        return null;
    }

    boolean useSelectedFields = (selectFields != null) && (selectFields.size() > 0);
    Map<String, Object> mappedEntity = new HashMap<String, Object>();
    for (Map.Entry<String, Object> mapEntry : tempEntity.entrySet()) {

        String key = mapEntry.getKey();
        if (useSelectedFields) {
            if (!selectFields.contains(key)) {
                continue;
            }
        }

        if (key.equalsIgnoreCase("id")) {
            continue;
        }

        Map<String, Object> namevalueDic = new HashMap<String, Object>();
        namevalueDic.put("name", key);
        namevalueDic.put("value", mapEntry.getValue());

        mappedEntity.put(key, namevalueDic);
    }

    return mappedEntity;
}
 
开发者ID:mattkol,项目名称:SugarOnRest,代码行数:44,代码来源:InsertEntry.java

示例9: jsonListSerialization

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
/**
 * Serialize a list of objects with all the class attributes 
 * @param objects
 * @return
 * @throws Exception 
 */
public static JsonNode jsonListSerialization(List<Program> objects) throws Exception
{
    ObjectMapper mapper = new ObjectMapper();
    DateFormat myDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
    mapper.setDateFormat(myDateFormat); 
    return mapper.convertValue(objects, JsonNode.class);
}
 
开发者ID:ejesposito,项目名称:CS6310O01,代码行数:14,代码来源:Program.java

示例10: jsonDesSerialization

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
/**
 * Des-Serialize an object who was in json format
 * @param jsonObject
 * @return
 * @throws Exception 
 */
public static Student jsonDesSerialization(JsonNode jsonObject) throws Exception
{
    Student object;
    ObjectMapper mapper = new ObjectMapper();
    DateFormat myDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
    mapper.setDateFormat(myDateFormat); 
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    object = mapper.convertValue(jsonObject,Student.class);
    return object;
}
 
开发者ID:ejesposito,项目名称:CS6310O01,代码行数:17,代码来源:Student.java

示例11: jsonDesSerialization

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
/**
 * Des-Serialize an object who was in json format
 * @param jsonObject
 * @return
 * @throws Exception 
 */
public static Role jsonDesSerialization(JsonNode jsonObject) throws Exception
{
    Role object;
    ObjectMapper mapper = new ObjectMapper();
    mapper.enableDefaultTyping();
    DateFormat myDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
    mapper.setDateFormat(myDateFormat); 
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    object = mapper.convertValue(jsonObject,Role.class);
    return object;
}
 
开发者ID:ejesposito,项目名称:CS6310O01,代码行数:18,代码来源:Role.java

示例12: jsonDesSerialization

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
/**
 * Des-Serialize an object who was in json format
 * @param jsonObject
 * @return
 * @throws Exception 
 */
public static Allocation jsonDesSerialization(JsonNode jsonObject) throws Exception
{
    Allocation object;
    ObjectMapper mapper = new ObjectMapper();
    DateFormat myDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
    mapper.setDateFormat(myDateFormat); 
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    object = mapper.convertValue(jsonObject,Allocation.class);
    return object;
}
 
开发者ID:ejesposito,项目名称:CS6310O01,代码行数:17,代码来源:Allocation.java

示例13: jsonListSerialization

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
/**
 * Serialize a list of objects with all the class attributes 
 * @param objects
 * @return
 * @throws Exception 
 */
public static JsonNode jsonListSerialization(List<CourseSession> objects) throws Exception
{
    ObjectMapper mapper = new ObjectMapper();
    DateFormat myDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
    mapper.setDateFormat(myDateFormat); 
    return mapper.convertValue(objects, JsonNode.class);
}
 
开发者ID:ejesposito,项目名称:CS6310O01,代码行数:14,代码来源:CourseSession.java

示例14: fetchUniversityAndAddToDatabase

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
private void fetchUniversityAndAddToDatabase() {
    if (sampleData == null) {
        // The sample data has not yet loaded. So notify user
        AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
        alertBuilder
                .setMessage(R.string.data_not_fetched)
                .setCancelable(true)
                .setNegativeButton ("Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {

                        finish();
                } }).show();
        return;

    }
    Random r = new Random();
    int index = r.nextInt(sampleData.size()-1);
    try {
        // 1. Get university object at randomly selected index
        University university = sampleData.get(index);

        // 2. Construct the document from university object
        ObjectMapper objectMapper = new ObjectMapper();

        // Ignore undeclared properties
        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

        HashMap<String,Object> universityMap = objectMapper.convertValue(university,HashMap.class);
        Document doc = new Document(universityMap);

        // 3. Save document to database.
        dbMgr.database.save(doc);
    }
    catch ( CouchbaseLiteException | NullPointerException e) {
        e.printStackTrace();
    }


}
 
开发者ID:couchbaselabs,项目名称:UniversityLister-Android,代码行数:40,代码来源:ListActivity.java

示例15: updateDatasetSecurity

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public static void updateDatasetSecurity(JsonNode root)
    throws Exception {
  final JsonNode security = root.path("securitySpecification");
  if (security.isMissingNode() || security.isNull()) {
    throw new IllegalArgumentException(
        "Dataset security info update fail, missing necessary fields: " + root.toString());
  }

  final Object[] idUrn = findDataset(root);
  if (idUrn[0] == null || idUrn[1] == null) {
    throw new IllegalArgumentException("Cannot identify dataset from id/uri/urn: " + root.toString());
  }
  final Integer datasetId = (Integer) idUrn[0];
  final String urn = (String) idUrn[1];

  ObjectMapper om = new ObjectMapper();

  DatasetSecurityRecord record = om.convertValue(security, DatasetSecurityRecord.class);
  record.setDatasetId(datasetId);
  record.setDatasetUrn(urn);
  record.setModifiedTime(System.currentTimeMillis() / 1000);
  try {
    DatasetSecurityRecord result = getDatasetSecurityByDatasetId(datasetId);
    String[] columns = record.getDbColumnNames();
    Object[] columnValues = record.getAllValuesToString();
    String[] conditions = {"dataset_id"};
    Object[] conditionValues = new Object[]{datasetId};
    SECURITY_WRITER.update(columns, columnValues, conditions, conditionValues);
  } catch (EmptyResultDataAccessException ex) {
    SECURITY_WRITER.append(record);
    SECURITY_WRITER.insert();
  }
}
 
开发者ID:thomas-young-2013,项目名称:wherehowsX,代码行数:34,代码来源:DatasetInfoDao.java


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