本文整理汇总了Java中org.nd4j.shade.jackson.databind.SerializationFeature类的典型用法代码示例。如果您正苦于以下问题:Java SerializationFeature类的具体用法?Java SerializationFeature怎么用?Java SerializationFeature使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SerializationFeature类属于org.nd4j.shade.jackson.databind包,在下文中一共展示了SerializationFeature类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toJacksonString
import org.nd4j.shade.jackson.databind.SerializationFeature; //导入依赖的package包/类
private String toJacksonString(JsonFactory factory) {
ObjectMapper om = new ObjectMapper(factory);
om.registerModule(new JodaModule());
om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
om.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
om.enable(SerializationFeature.INDENT_OUTPUT);
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE);
om.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
String str;
try {
str = om.writeValueAsString(this);
} catch (Exception e) {
throw new RuntimeException(e);
}
return str;
}
示例2: testJson
import org.nd4j.shade.jackson.databind.SerializationFeature; //导入依赖的package包/类
@Test
public void testJson() throws Exception {
ObjectMapper om = new ObjectMapper();
om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
om.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
om.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
om.enable(SerializationFeature.INDENT_OUTPUT);
ISchedule[] schedules = new ISchedule[]{
new ExponentialSchedule(ScheduleType.ITERATION, 1.0, 0.5),
new InverseSchedule(ScheduleType.ITERATION, 1.0, 0.5, 2),
new MapSchedule.Builder(ScheduleType.ITERATION).add(0, 1.0).add(10,0.5).build(),
new PolySchedule(ScheduleType.ITERATION, 1.0, 2, 100),
new SigmoidSchedule(ScheduleType.ITERATION, 1.0, 0.5, 10),
new StepSchedule(ScheduleType.ITERATION, 1.0, 0.9, 100)};
for(ISchedule s : schedules){
String json = om.writeValueAsString(s);
ISchedule fromJson = om.readValue(json, ISchedule.class);
assertEquals(s, fromJson);
}
}
示例3: testJsonSerialization
import org.nd4j.shade.jackson.databind.SerializationFeature; //导入依赖的package包/类
@Test
public void testJsonSerialization() throws Exception {
INDArray w = Nd4j.create(new double[] {1.0, 2.0, 3.0});
ILossFunction[] lossFns = new ILossFunction[] {new LossBinaryXENT(), new LossBinaryXENT(w),
new LossCosineProximity(), new LossHinge(), new LossKLD(), new LossL1(), new LossL1(w),
new LossL2(), new LossL2(w), new LossMAE(), new LossMAE(w), new LossMAPE(), new LossMAPE(w),
new LossMCXENT(), new LossMCXENT(w), new LossMSE(), new LossMSE(w), new LossMSLE(),
new LossMSLE(w), new LossNegativeLogLikelihood(), new LossNegativeLogLikelihood(w),
new LossPoisson(), new LossSquaredHinge()};
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
mapper.enable(SerializationFeature.INDENT_OUTPUT);
for (ILossFunction lf : lossFns) {
String asJson = mapper.writeValueAsString(lf);
// System.out.println(asJson);
ILossFunction fromJson = mapper.readValue(asJson, ILossFunction.class);
assertEquals(lf, fromJson);
}
}
示例4: configureMapper
import org.nd4j.shade.jackson.databind.SerializationFeature; //导入依赖的package包/类
private static ObjectMapper configureMapper(ObjectMapper ret) {
ret.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
ret.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
ret.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, false);
ret.enable(SerializationFeature.INDENT_OUTPUT);
SimpleModule atomicModule = new SimpleModule();
atomicModule.addSerializer(AtomicDouble.class,new JsonSerializerAtomicDouble());
atomicModule.addSerializer(AtomicBoolean.class,new JsonSerializerAtomicBoolean());
atomicModule.addDeserializer(AtomicDouble.class,new JsonDeserializerAtomicDouble());
atomicModule.addDeserializer(AtomicBoolean.class,new JsonDeserializerAtomicBoolean());
ret.registerModule(atomicModule);
//Serialize fields only, not using getters
ret.setVisibilityChecker(ret.getSerializationConfig().getDefaultVisibilityChecker()
.withFieldVisibility(JsonAutoDetect.Visibility.ANY)
.withGetterVisibility(JsonAutoDetect.Visibility.NONE)
.withSetterVisibility(JsonAutoDetect.Visibility.NONE)
.withCreatorVisibility(JsonAutoDetect.Visibility.NONE));
return ret;
}
示例5: initMapper
import org.nd4j.shade.jackson.databind.SerializationFeature; //导入依赖的package包/类
private static ObjectMapper initMapper(JsonFactory factory) {
ObjectMapper om = new ObjectMapper(factory);
om.registerModule(new JodaModule());
om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
om.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
om.enable(SerializationFeature.INDENT_OUTPUT);
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE);
om.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
return om;
}
示例6: fromJacksonString
import org.nd4j.shade.jackson.databind.SerializationFeature; //导入依赖的package包/类
private static Schema fromJacksonString(String str, JsonFactory factory) {
ObjectMapper om = new ObjectMapper(factory);
om.registerModule(new JodaModule());
om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
om.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
om.enable(SerializationFeature.INDENT_OUTPUT);
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE);
om.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
try {
return om.readValue(str, Schema.class);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例7: getObjectMapper
import org.nd4j.shade.jackson.databind.SerializationFeature; //导入依赖的package包/类
protected ObjectMapper getObjectMapper(JsonFactory factory) {
ObjectMapper om = new ObjectMapper(factory);
om.registerModule(new JodaModule());
om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
om.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
om.enable(SerializationFeature.INDENT_OUTPUT);
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE);
om.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
return om;
}
示例8: initMapper
import org.nd4j.shade.jackson.databind.SerializationFeature; //导入依赖的package包/类
/**
* Clone of initMapper used for serialization and deserialization
* of TransformProcess class, to support unit testing of
* serialization and deserializtion of individual transforms.
*
* @param factory JsonFactory
* @return ObjectMapper for serde of transforms
*/
public static ObjectMapper initMapper(JsonFactory factory) {
ObjectMapper om = new ObjectMapper(new JsonFactory());
om.registerModule(new JodaModule());
om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
om.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
om.enable(SerializationFeature.INDENT_OUTPUT);
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE);
om.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
return om;
}
示例9: getModelMapper
import org.nd4j.shade.jackson.databind.SerializationFeature; //导入依赖的package包/类
private static ObjectMapper getModelMapper() {
ObjectMapper ret = new ObjectMapper();
ret.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
ret.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
ret.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
ret.enable(SerializationFeature.INDENT_OUTPUT);
return ret;
}
示例10: mapper
import org.nd4j.shade.jackson.databind.SerializationFeature; //导入依赖的package包/类
public static ObjectMapper mapper() {
/*
DO NOT ENABLE INDENT_OUTPUT FEATURE
we need THIS json to be single-line
*/
ObjectMapper ret = new ObjectMapper();
ret.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
ret.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
ret.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
return ret;
}
示例11: renderHTMLContent
import org.nd4j.shade.jackson.databind.SerializationFeature; //导入依赖的package包/类
public static String renderHTMLContent(Component... components) throws Exception {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
mapper.enable(SerializationFeature.INDENT_OUTPUT);
Configuration cfg = new Configuration(new Version(2, 3, 23));
// Where do we load the templates from:
cfg.setClassForTemplateLoading(StaticPageUtil.class, "");
// Some other recommended settings:
cfg.setIncompatibleImprovements(new Version(2, 3, 23));
cfg.setDefaultEncoding("UTF-8");
cfg.setLocale(Locale.US);
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
ClassPathResource cpr = new ClassPathResource("assets/dl4j-ui.js");
String scriptContents = IOUtils.toString(cpr.getInputStream(), "UTF-8");
Map<String, Object> pageElements = new HashMap<>();
List<ComponentObject> list = new ArrayList<>();
int i = 0;
for (Component c : components) {
list.add(new ComponentObject(String.valueOf(i), mapper.writeValueAsString(c)));
i++;
}
pageElements.put("components", list);
pageElements.put("scriptcontent", scriptContents);
Template template = cfg.getTemplate("staticpage.ftl");
Writer stringWriter = new StringWriter();
template.process(pageElements, stringWriter);
return stringWriter.toString();
}
示例12: getNewMapper
import org.nd4j.shade.jackson.databind.SerializationFeature; //导入依赖的package包/类
protected static ObjectMapper getNewMapper(JsonFactory jsonFactory) {
ObjectMapper om = new ObjectMapper(jsonFactory);
om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
om.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
om.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
om.enable(SerializationFeature.INDENT_OUTPUT);
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE);
om.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
return om;
}