本文整理匯總了Java中com.fasterxml.jackson.databind.DeserializationFeature類的典型用法代碼示例。如果您正苦於以下問題:Java DeserializationFeature類的具體用法?Java DeserializationFeature怎麽用?Java DeserializationFeature使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DeserializationFeature類屬於com.fasterxml.jackson.databind包,在下文中一共展示了DeserializationFeature類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: read
import com.fasterxml.jackson.databind.DeserializationFeature; //導入依賴的package包/類
public static SecurityAnalysisResult read(Path jsonFile) {
Objects.requireNonNull(jsonFile);
try (InputStream is = Files.newInputStream(jsonFile)) {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING);
SimpleModule module = new SimpleModule();
module.addDeserializer(SecurityAnalysisResult.class, new SecurityAnalysisResultDeserializer());
module.addDeserializer(NetworkMetadata.class, new NetworkMetadataDeserializer());
module.addDeserializer(PostContingencyResult.class, new PostContingencyResultDeserializer());
module.addDeserializer(LimitViolationsResult.class, new LimitViolationResultDeserializer());
module.addDeserializer(LimitViolation.class, new LimitViolationDeserializer());
module.addDeserializer(Contingency.class, new ContingencyDeserializer());
module.addDeserializer(ContingencyElement.class, new ContingencyElementDeserializer());
objectMapper.registerModule(module);
return objectMapper.readValue(is, SecurityAnalysisResult.class);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
示例2: readInternal
import com.fasterxml.jackson.databind.DeserializationFeature; //導入依賴的package包/類
protected <R extends Object> R readInternal(final DocumentDbPersistentEntity<?> entity, Class<R> type,
final Document sourceDocument) {
final ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
try {
final DocumentDbPersistentProperty idProperty = entity.getIdProperty();
final Object idValue = sourceDocument.getId();
final JSONObject jsonObject = new JSONObject(sourceDocument.toJson());
if (idProperty != null) {
// Replace the key id to the actual id field name in domain
jsonObject.remove("id");
jsonObject.put(idProperty.getName(), idValue);
}
return objectMapper.readValue(jsonObject.toString(), type);
} catch (IOException e) {
throw new IllegalStateException("Failed to read the source document " + sourceDocument.toJson()
+ " to target type " + type, e);
}
}
示例3: deserializeFromIndexFiles
import com.fasterxml.jackson.databind.DeserializationFeature; //導入依賴的package包/類
protected List<PackageMetadata> deserializeFromIndexFiles(List<File> indexFiles) {
List<PackageMetadata> packageMetadataList = new ArrayList<>();
YAMLMapper yamlMapper = new YAMLMapper();
yamlMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
for (File indexFile : indexFiles) {
try {
MappingIterator<PackageMetadata> it = yamlMapper.readerFor(PackageMetadata.class).readValues(indexFile);
while (it.hasNextValue()) {
PackageMetadata packageMetadata = it.next();
packageMetadataList.add(packageMetadata);
}
}
catch (IOException e) {
throw new IllegalArgumentException("Can't parse Release manifest YAML", e);
}
}
return packageMetadataList;
}
示例4: CommentUserEventService
import com.fasterxml.jackson.databind.DeserializationFeature; //導入依賴的package包/類
@Inject
public CommentUserEventService(Duniter4jClient client,
PluginSettings settings,
CryptoService cryptoService,
UserService userService,
UserEventService userEventService) {
super("duniter.user.event.comment", client, settings, cryptoService);
this.userService = userService;
this.userEventService = userEventService;
objectMapper = JacksonUtils.newObjectMapper()
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
this.changeListenSources = ImmutableList.of(
new ChangeSource(MarketIndexDao.INDEX, MarketCommentDao.TYPE),
new ChangeSource(RegistryIndexDao.INDEX, RegistryCommentDao.TYPE));
ChangeService.registerListener(this);
this.trace = logger.isTraceEnabled();
this.recordType = RecordDao.TYPE;
}
示例5: getAppStatusList
import com.fasterxml.jackson.databind.DeserializationFeature; //導入依賴的package包/類
@JsonIgnore
public List<AppStatus> getAppStatusList() {
try {
ObjectMapper mapper = new ObjectMapper();
mapper.addMixIn(AppStatus.class, AppStatusMixin.class);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
SimpleModule module = new SimpleModule("CustomModel", Version.unknownVersion());
SimpleAbstractTypeResolver resolver = new SimpleAbstractTypeResolver();
resolver.addMapping(AppInstanceStatus.class, AppInstanceStatusImpl.class);
module.setAbstractTypes(resolver);
mapper.registerModule(module);
TypeReference<List<AppStatus>> typeRef = new TypeReference<List<AppStatus>>() {
};
if (this.platformStatus != null) {
return mapper.readValue(this.platformStatus, typeRef);
}
return new ArrayList<AppStatus>();
}
catch (Exception e) {
throw new IllegalArgumentException("Could not parse Skipper Platfrom Status JSON:" + platformStatus, e);
}
}
示例6: provideObjectMapper
import com.fasterxml.jackson.databind.DeserializationFeature; //導入依賴的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;
}
示例7: doInBackground
import com.fasterxml.jackson.databind.DeserializationFeature; //導入依賴的package包/類
@Override
protected String doInBackground(Void... params) {
ObjectMapper objectMapper = new ObjectMapper().disable(DeserializationFeature.FAIL_ON_MISSING_CREATOR_PROPERTIES).disable(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES);
String comentarioJSON="";
//Construyo el JSON
try {
comentarioJSON = objectMapper.writeValueAsString(comentario);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
String resultado = null;
//Cojo el resultado en un String
resultado = ConsultasBBDD.hacerConsulta(ConsultasBBDD.insertaComentario, comentarioJSON, "POST");
return resultado;
}
示例8: getRestTemplate
import com.fasterxml.jackson.databind.DeserializationFeature; //導入依賴的package包/類
protected RestTemplate getRestTemplate() {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.registerModule(new Jackson2HalModule());
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
converter.setSupportedMediaTypes(Arrays.asList(MediaTypes.HAL_JSON));
converter.setObjectMapper(mapper);
return new RestTemplate(Collections.<HttpMessageConverter<?>>singletonList(converter));
}
示例9: DefaultLicenseManager
import com.fasterxml.jackson.databind.DeserializationFeature; //導入依賴的package包/類
public DefaultLicenseManager(String publicKey) {
this.currentVersion = DefaultLicenseManager.LicenseVersion.PRODUCT_SIGNATURE_VERSION;
this.registeredProducts = new LinkedList();
this.loadedLicenses = new HashMap();
this.productToActiveLicenseMap = new HashMap();
this.productToStarterLicenseMap = new HashMap();
this.licenseManagerListeners = new LinkedList();
try {
X509EncodedKeySpec e = new X509EncodedKeySpec(Base.decode(publicKey == null?"H4sIAAAAAAAAAAEmAdn+MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA58/mQ8VjKWDj9ai3mTzFX0b2S0VbV7LIQFv97U8ePdFoLu/cAcTvw7jsvQAT/3RHS7kzXXOk4OGDb7rmL85Dw6nfDs1jFA1auvrICW2vvOdpLrOOijJX5S5EJWHxKoBXSOfxU/fKFa93iuSVKJdqXJeah2Lgs/wq54BBcp4SrxogwWiuqFImqDo7BZKAZgLSm/v2IlICxKGM9QgAoYYLL/bongBpp6SxTy1gm/YD108jJxEk5wuFefDPDMlP0kioSsmGonU6o++pqYLuLkbFdNOdbmtoTphzP5vNaLaTQBmw9vuFHqh80BmIEQi6pK/Wz2RjOU6CYDpn9wv1Lgo2JQIDAQABbOI6ryYBAAA=":publicKey));
KeyFactory kf = KeyFactory.getInstance("RSA");
this.publicKey = kf.generatePublic(e);
} catch (InvalidKeySpecException | IOException | NoSuchAlgorithmException var4) {
throw new IllegalStateException("PublicKey could not be initialized.", var4);
}
this.jsonObjectMapper = new ObjectMapper();
this.licenseAnnotationValidator = new LicenseAnnotationValidator(this);
this.jsonObjectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}
示例10: setUp
import com.fasterxml.jackson.databind.DeserializationFeature; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
mapper = Jackson2ObjectMapperBuilder.json()
.featuresToDisable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE)
.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.build();
mapper.findAndRegisterModules();
}
示例11: JsonMapper
import com.fasterxml.jackson.databind.DeserializationFeature; //導入依賴的package包/類
public JsonMapper() {
// calls the default constructor
super();
// configures ISO8601 formatter for date without time zone
// the used format is 'yyyy-MM-dd'
super.setDateFormat(new SimpleDateFormat(FMT_ISO_LOCAL_DATE));
// enforces to skip null and empty values in the serialized JSON output
super.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
// enforces to skip null references in the serialized output of Map
super.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
// enables serialization failures, when mapper encounters unknown properties names
super.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true);
// configures the format to prevent writing of the serialized output for java.util.Date
// instances as timestamps. any date should be written in ISO format
super.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
}
示例12: configureerMapper
import com.fasterxml.jackson.databind.DeserializationFeature; //導入依賴的package包/類
private void configureerMapper() {
// Configuratie
this.disable(MapperFeature.AUTO_DETECT_CREATORS);
this.disable(MapperFeature.AUTO_DETECT_FIELDS);
this.disable(MapperFeature.AUTO_DETECT_GETTERS);
this.disable(MapperFeature.AUTO_DETECT_IS_GETTERS);
this.disable(MapperFeature.AUTO_DETECT_SETTERS);
// Default velden niet als JSON exposen (expliciet annoteren!)
setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.NONE);
this.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY);
this.enable(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS);
// serialization
this.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
this.enable(SerializationFeature.WRITE_ENUMS_USING_INDEX);
// deserialization
this.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
}
示例13: loadGenesisJson
import com.fasterxml.jackson.databind.DeserializationFeature; //導入依賴的package包/類
public static GenesisJson loadGenesisJson(InputStream genesisJsonIS) throws RuntimeException {
String json = null;
try {
json = new String(ByteStreams.toByteArray(genesisJsonIS));
ObjectMapper mapper = new ObjectMapper()
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES);
GenesisJson genesisJson = mapper.readValue(json, GenesisJson.class);
return genesisJson;
} catch (Exception e) {
Utils.showErrorAndExit("Problem parsing genesis: "+ e.getMessage(), json);
throw new RuntimeException(e.getMessage(), e);
}
}
示例14: getAccounts
import com.fasterxml.jackson.databind.DeserializationFeature; //導入依賴的package包/類
public List<Account> getAccounts() {
final Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
final ObjectMapper mapper = new ObjectMapper()
.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
List<Account> accounts = null;
try {
accounts = mapper.readValue(rulesFile,
new TypeReference<List<Account>>() {});
if (accounts != null) {
accounts.forEach((account) -> {
final Set<ConstraintViolation<Account>> accountViolations = validator.validate(account);
if (accountViolations.size() > 0) {
throw new AccountValidationException(accountViolations);
}
account.getRules().sort((o1, o2) -> o1.getType().compareTo(o2.getType()));
});
}
} catch (IOException ex) {
Logger.getLogger(AccountService.class.getName()).log(Level.SEVERE, null, ex);
}
return accounts;
}
示例15: doInBackground
import com.fasterxml.jackson.databind.DeserializationFeature; //導入依賴的package包/類
@Override
protected EpubPublication doInBackground(String... urls) {
String strUrl = urls[0];
try {
URL url = new URL(strUrl);
URLConnection urlConnection = url.openConnection();
InputStream inputStream = urlConnection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
StringBuilder stringBuilder = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
stringBuilder.append(line);
}
Log.d("TestActivity", "EpubPublication => " + stringBuilder.toString());
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
return objectMapper.readValue(stringBuilder.toString(), EpubPublication.class);
} catch (IOException e) {
Log.e(TAG, "SpineListTask error " + e);
}
return null;
}