當前位置: 首頁>>代碼示例>>Java>>正文


Java DeserializationFeature類代碼示例

本文整理匯總了Java中org.nd4j.shade.jackson.databind.DeserializationFeature的典型用法代碼示例。如果您正苦於以下問題:Java DeserializationFeature類的具體用法?Java DeserializationFeature怎麽用?Java DeserializationFeature使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DeserializationFeature類屬於org.nd4j.shade.jackson.databind包,在下文中一共展示了DeserializationFeature類的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: toJacksonString

import org.nd4j.shade.jackson.databind.DeserializationFeature; //導入依賴的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;
}
 
開發者ID:deeplearning4j,項目名稱:DataVec,代碼行數:18,代碼來源:Schema.java

示例2: testJson

import org.nd4j.shade.jackson.databind.DeserializationFeature; //導入依賴的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);
    }
}
 
開發者ID:deeplearning4j,項目名稱:nd4j,代碼行數:25,代碼來源:TestSchedules.java

示例3: testJsonSerialization

import org.nd4j.shade.jackson.databind.DeserializationFeature; //導入依賴的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);
    }
}
 
開發者ID:deeplearning4j,項目名稱:nd4j,代碼行數:27,代碼來源:LossFunctionJson.java

示例4: configureMapper

import org.nd4j.shade.jackson.databind.DeserializationFeature; //導入依賴的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;
}
 
開發者ID:deeplearning4j,項目名稱:deeplearning4j,代碼行數:20,代碼來源:BaseEvaluation.java

示例5: initMapper

import org.nd4j.shade.jackson.databind.DeserializationFeature; //導入依賴的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;
}
 
開發者ID:deeplearning4j,項目名稱:DataVec,代碼行數:11,代碼來源:ImageTransformProcess.java

示例6: fromJacksonString

import org.nd4j.shade.jackson.databind.DeserializationFeature; //導入依賴的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);
    }
}
 
開發者ID:deeplearning4j,項目名稱:DataVec,代碼行數:15,代碼來源:Schema.java

示例7: getObjectMapper

import org.nd4j.shade.jackson.databind.DeserializationFeature; //導入依賴的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;
}
 
開發者ID:deeplearning4j,項目名稱:DataVec,代碼行數:11,代碼來源:BaseSerializer.java

示例8: initMapper

import org.nd4j.shade.jackson.databind.DeserializationFeature; //導入依賴的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;
}
 
開發者ID:deeplearning4j,項目名稱:DataVec,代碼行數:19,代碼來源:TestUtil.java

示例9: readAttributeAsJson

import org.nd4j.shade.jackson.databind.DeserializationFeature; //導入依賴的package包/類
/**
 * Read JSON-formatted string attribute.
 *
 * @param attribute     HDF5 attribute to read as JSON formatted string.
 * @return
 * @throws UnsupportedKerasConfigurationException
 */
private String readAttributeAsJson(hdf5.Attribute attribute) throws UnsupportedKerasConfigurationException {
    hdf5.VarLenType vl = attribute.getVarLenType();
    int bufferSizeMult = 1;
    String s = null;
    /* TODO: find a less hacky way to do this.
     * Reading variable length strings (from attributes) is a giant
     * pain. There does not appear to be any way to determine the
     * length of the string in advance, so we use a hack: choose a
     * buffer size and read the config. If Jackson fails to parse
     * it, then we must not have read the entire config. Increase
     * buffer and repeat.
     */
    while (true) {
        byte[] attrBuffer = new byte[bufferSizeMult * 2000];
        BytePointer attrPointer = new BytePointer(attrBuffer);
        attribute.read(vl, attrPointer);
        attrPointer.get(attrBuffer);
        s = new String(attrBuffer);
        ObjectMapper mapper = new ObjectMapper();
        mapper.enable(DeserializationFeature.FAIL_ON_READING_DUP_TREE_KEY);
        try {
            mapper.readTree(s);
            break;
        } catch (IOException e) {
        }
        bufferSizeMult++;
        if (bufferSizeMult > 100) {
            throw new UnsupportedKerasConfigurationException("Could not read abnormally long HDF5 attribute");
        }
    }
    return s;
}
 
開發者ID:deeplearning4j,項目名稱:deeplearning4j,代碼行數:40,代碼來源:Hdf5Archive.java

示例10: getModelMapper

import org.nd4j.shade.jackson.databind.DeserializationFeature; //導入依賴的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;
}
 
開發者ID:deeplearning4j,項目名稱:deeplearning4j,代碼行數:9,代碼來源:WordVectorSerializer.java

示例11: mapper

import org.nd4j.shade.jackson.databind.DeserializationFeature; //導入依賴的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;
}
 
開發者ID:deeplearning4j,項目名稱:deeplearning4j,代碼行數:12,代碼來源:SequenceElement.java

示例12: renderHTMLContent

import org.nd4j.shade.jackson.databind.DeserializationFeature; //導入依賴的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();
    }
 
開發者ID:deeplearning4j,項目名稱:deeplearning4j,代碼行數:40,代碼來源:StaticPageUtil.java

示例13: getNewMapper

import org.nd4j.shade.jackson.databind.DeserializationFeature; //導入依賴的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;
}
 
開發者ID:deeplearning4j,項目名稱:deeplearning4j,代碼行數:11,代碼來源:BaseTrainingMaster.java


注:本文中的org.nd4j.shade.jackson.databind.DeserializationFeature類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。