本文整理匯總了Java中com.fasterxml.jackson.databind.PropertyNamingStrategy類的典型用法代碼示例。如果您正苦於以下問題:Java PropertyNamingStrategy類的具體用法?Java PropertyNamingStrategy怎麽用?Java PropertyNamingStrategy使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
PropertyNamingStrategy類屬於com.fasterxml.jackson.databind包,在下文中一共展示了PropertyNamingStrategy類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: insertDataset
import com.fasterxml.jackson.databind.PropertyNamingStrategy; //導入依賴的package包/類
public static void insertDataset(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.append(record);
dw.close();
}
示例2: setDatasetRecord
import com.fasterxml.jackson.databind.PropertyNamingStrategy; //導入依賴的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);
}
}
}
示例3: updateDataset
import com.fasterxml.jackson.databind.PropertyNamingStrategy; //導入依賴的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();
}
示例4: insertDataset
import com.fasterxml.jackson.databind.PropertyNamingStrategy; //導入依賴的package包/類
public static void insertDataset(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());
}
}
// Find layout id
if (record.getSamplePartitionFullPath() != null) {
PartitionPatternMatcher ppm = new PartitionPatternMatcher(PartitionLayoutDao.getPartitionLayouts());
record.setPartitionLayoutPatternId(ppm.analyze(record.getSamplePartitionFullPath()));
}
DatabaseWriter dw = new DatabaseWriter(JdbcUtil.wherehowsJdbcTemplate, "dict_dataset");
dw.append(record);
dw.close();
}
示例5: setDatasetRecord
import com.fasterxml.jackson.databind.PropertyNamingStrategy; //導入依賴的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());
try {
Map<String, Object> result = JdbcUtil.wherehowsNamedJdbcTemplate.queryForMap(GET_DATASET_BY_URN, params);
updateDataset(dataset);
} catch (EmptyResultDataAccessException e) {
insertDataset(dataset);
}
}
}
示例6: updateDataset
import com.fasterxml.jackson.databind.PropertyNamingStrategy; //導入依賴的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());
}
}
// Find layout id
if (record.getSamplePartitionFullPath() != null) {
PartitionPatternMatcher ppm = new PartitionPatternMatcher(PartitionLayoutDao.getPartitionLayouts());
record.setPartitionLayoutPatternId(ppm.analyze(record.getSamplePartitionFullPath()));
}
DatabaseWriter dw = new DatabaseWriter(JdbcUtil.wherehowsJdbcTemplate, "dict_dataset");
dw.update(record.toUpdateDatabaseValue(), record.getUrn());
dw.close();
}
示例7: load
import com.fasterxml.jackson.databind.PropertyNamingStrategy; //導入依賴的package包/類
protected void load(final String dataDir, final boolean update) {
try {
final File dir = new File("data/fixtures/" + dataDir);
final File[] files = dir.listFiles((d, name) -> name.endsWith(".json"));
if (files == null) {
throw new IOException("No files found in " + dir.getAbsolutePath());
}
final ObjectMapper mapper = new ObjectMapper();
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
for (File jsonFile : files) {
final T entity = mapper.readValue(jsonFile, entityClass);
if (update && entity.getId() != null) {
update(entity);
} else {
create(entity);
}
}
} catch (IOException ioex) {
throw new RuntimeException(ioex);
}
}
示例8: objectMapper
import com.fasterxml.jackson.databind.PropertyNamingStrategy; //導入依賴的package包/類
public static ObjectMapper objectMapper() {
return new ObjectMapper()
// Property visibility
.setDefaultPropertyInclusion(JsonInclude.Include.ALWAYS)
.setDefaultVisibility(JsonAutoDetect.Value.construct(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.PROTECTED_AND_PUBLIC))
.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true)
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, true)
// Property naming and order
.setPropertyNamingStrategy(PropertyNamingStrategy.LOWER_CAMEL_CASE)
// Customised de/serializers
// Formats, locals, encoding, binary data
.setDateFormat(new SimpleDateFormat("MM/dd/yyyy"))
.setDefaultPrettyPrinter(new DefaultPrettyPrinter())
.setLocale(Locale.CANADA);
}
示例9: createCluster
import com.fasterxml.jackson.databind.PropertyNamingStrategy; //導入依賴的package包/類
public Optional<Cluster> createCluster(String name, String region, Map<String, String> args)
throws IOException {
Map<String, String> createOptions = new HashMap<>(args);
createOptions.put(SpydraArgument.OPTION_REGION, region);
List<String> command = ImmutableList.of("--format=json", "beta", "dataproc", "clusters", "create", name);
StringBuilder outputBuilder = new StringBuilder();
boolean success = ProcessHelper.executeForOutput(
buildCommand(command, createOptions, Collections.emptyList()),
outputBuilder);
String output = outputBuilder.toString();
if (success) {
Cluster cluster = JsonHelper.objectMapper()
.setPropertyNamingStrategy(PropertyNamingStrategy.LOWER_CAMEL_CASE)
.readValue(output, Cluster.class);
return Optional.of(cluster);
} else {
LOGGER.error("Dataproc cluster creation call failed. Command line output:");
LOGGER.error(output);
return Optional.empty();
}
}
示例10: createDefaultMapper
import com.fasterxml.jackson.databind.PropertyNamingStrategy; //導入依賴的package包/類
public static ObjectMapper createDefaultMapper() {
final ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(Include.NON_NULL);
mapper.configure(SerializationFeature.INDENT_OUTPUT, false);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
SimpleModule module = new SimpleModule();
module.addSerializer(Transaction.class, new TransactionSerializer());
module.addDeserializer(Transaction.class, new TransactionDeserializer());
module.addSerializer(Difficulty.class, new DifficultySerializer());
module.addDeserializer(Difficulty.class, new DifficultyDeserializer());
module.addSerializer(Block.class, new BlockSerializer());
module.addDeserializer(Block.class, new BlockDeserializer());
mapper.registerModule(module);
return mapper;
}
示例11: fieldNamingStrategySerialize
import com.fasterxml.jackson.databind.PropertyNamingStrategy; //導入依賴的package包/類
@Test
public void fieldNamingStrategySerialize() throws IOException {
final ObjectMapper mapper = new VPackMapper();
mapper.setPropertyNamingStrategy(new PropertyNamingStrategy() {
private static final long serialVersionUID = 1L;
@Override
public String nameForGetterMethod(
final MapperConfig<?> config,
final AnnotatedMethod method,
final String defaultName) {
return "bla";
}
});
final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(new TestEntityA()));
assertThat(vpack, is(notNullValue()));
assertThat(vpack.isObject(), is(true));
final VPackSlice bla = vpack.get("bla");
assertThat(bla.isString(), is(true));
assertThat(bla.getAsString(), is("a"));
}
示例12: fieldNamingStrategyDeserialize
import com.fasterxml.jackson.databind.PropertyNamingStrategy; //導入依賴的package包/類
@Test
public void fieldNamingStrategyDeserialize() throws IOException {
final VPackBuilder builder = new VPackBuilder();
builder.add(ValueType.OBJECT);
builder.add("bla", "test");
builder.close();
final ObjectMapper mapper = new VPackMapper();
mapper.setPropertyNamingStrategy(new PropertyNamingStrategy() {
private static final long serialVersionUID = 1L;
@Override
public String nameForSetterMethod(
final MapperConfig<?> config,
final AnnotatedMethod method,
final String defaultName) {
return "bla";
}
});
final TestEntityA entity = mapper.readValue(builder.slice().getBuffer(), TestEntityA.class);
assertThat(entity, is(notNullValue()));
assertThat(entity.a, is("test"));
}
示例13: newInstance
import com.fasterxml.jackson.databind.PropertyNamingStrategy; //導入依賴的package包/類
/**
* Creates properly configured Jackson XML Mapper instances.
* @return XmlMapper instance.
*/
public static XmlMapper newInstance() {
// Create new mapper
final JacksonXmlModule module = new JacksonXmlModule();
module.setDefaultUseWrapper(false);
XmlMapper mapper = new XmlMapper(module);
// Configure it
mapper
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE)
.registerModule(new JodaModule())
.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
return mapper;
}
示例14: provideObjectMapper
import com.fasterxml.jackson.databind.PropertyNamingStrategy; //導入依賴的package包/類
public ObjectMapper provideObjectMapper() {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
objectMapper.setSerializationInclusion(Include.NON_NULL);
objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
objectMapper.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true);
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
objectMapper.setDateFormat(provideDateFormat());
return objectMapper;
}
示例15: decryptUserInfo
import com.fasterxml.jackson.databind.PropertyNamingStrategy; //導入依賴的package包/類
public WxAppUserInfoRes decryptUserInfo(String encryptedData, String iv, String sessionKey) {
byte[] res = WechatAESUtils.decrypt(Base64.decodeBase64(encryptedData),
Base64.decodeBase64(sessionKey), Base64.decodeBase64(iv));
if (null != res && res.length > 0) {
try {
String resStr = new String(res, "UTF8");
return getObjectMapper()
.setPropertyNamingStrategy(PropertyNamingStrategy.LOWER_CAMEL_CASE)
.readValue(resStr, WxAppUserInfoRes.class);
} catch (IOException e) {
logger.error(e.getMessage(), e);
return null;
}
}
return null;
}