org.nd4j.shade.jackson.dataformat.yaml.YAMLFactory Java Examples

The following examples show how to use org.nd4j.shade.jackson.dataformat.yaml.YAMLFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ObjectMappers.java    From konduit-serving with Apache License 2.0 6 votes vote down vote up
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);         //Use order in which fields are defined in classes
    ret.enable(SerializationFeature.INDENT_OUTPUT);
    ret.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE);
    ret.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
    ret.setVisibility(PropertyAccessor.CREATOR, JsonAutoDetect.Visibility.ANY);
    ret.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    if (ret.getFactory() instanceof YAMLFactory) {
        ret.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
    }

    ret.configure(SerializationFeature.FAIL_ON_UNWRAPPED_TYPE_IDENTIFIERS, false);

    //Configure subtypes - via service loader from other modules
    List<JsonSubType> l = getAllSubtypes();
    for(JsonSubType t : l){
        NamedType nt = new NamedType(t.getSubtype(), t.getName());
        ret.registerSubtypes(nt);
    }

    return ret;
}
 
Example #2
Source File: JacksonRecordReaderTest.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
@Test
public void testReadingYaml() throws Exception {
    //Exact same information as JSON format, but in YAML format

    ClassPathResource cpr = new ClassPathResource("datavec-api/yaml/");
    File f = testDir.newFolder();
    cpr.copyDirectory(f);
    String path = new File(f, "yaml_test_%d.txt").getAbsolutePath();


    InputSplit is = new NumberedFileInputSplit(path, 0, 2);

    RecordReader rr = new JacksonRecordReader(getFieldSelection(), new ObjectMapper(new YAMLFactory()));
    rr.initialize(is);

    testJacksonRecordReader(rr);
}
 
Example #3
Source File: ObjectMappers.java    From konduit-serving with Apache License 2.0 5 votes vote down vote up
private static ObjectMapper configureMapper(ObjectMapper ret) {
    ret.registerModule(new JodaModule());
    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);
    ret.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE);
    ret.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
    ret.setVisibility(PropertyAccessor.CREATOR, JsonAutoDetect.Visibility.ANY);
    ret.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    if(ret.getFactory() instanceof YAMLFactory) {
        ret.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
    }
    return ret;
}
 
Example #4
Source File: ObjectMappers.java    From konduit-serving with Apache License 2.0 5 votes vote down vote up
/**
 * Register JSON subtypes manually. Mainly used for testing purposes.
 * In general ServiceLoader should be used for registering JSON subtypes.
 *
 * @param subTypes Subtypes to register manually
 */
public static void registerSubtypes(@NonNull List<JsonSubType> subTypes){
    manuallyRegisteredSubtypes.addAll(subTypes);
    jsonMapper = configureMapper(new ObjectMapper());
    yamlMapper = configureMapper(new ObjectMapper(new YAMLFactory()
            .disable(YAMLGenerator.Feature.USE_NATIVE_TYPE_ID)  // For preventing YAML from adding `!<TYPE>` with polymorphic objects
            // and use Jackson's type information mechanism.
    ));
}
 
Example #5
Source File: JacksonRecordReaderTest.java    From DataVec with Apache License 2.0 5 votes vote down vote up
@Test
public void testReadingYaml() throws Exception {
    //Exact same information as JSON format, but in YAML format

    ClassPathResource cpr = new ClassPathResource("yaml/yaml_test_0.txt");
    String path = cpr.getFile().getAbsolutePath().replace("0", "%d");

    InputSplit is = new NumberedFileInputSplit(path, 0, 2);

    RecordReader rr = new JacksonRecordReader(getFieldSelection(), new ObjectMapper(new YAMLFactory()));
    rr.initialize(is);

    testJacksonRecordReader(rr);
}
 
Example #6
Source File: BaseTrainingMaster.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
protected static synchronized ObjectMapper getYamlMapper() {
    if (yamlMapper == null) {
        yamlMapper = getNewMapper(new YAMLFactory());
    }
    return yamlMapper;
}
 
Example #7
Source File: KerasModelUtils.java    From deeplearning4j with Apache License 2.0 3 votes vote down vote up
/**
 * Convenience function for parsing YAML strings.
 *
 * @param yaml String containing valid YAML
 * @return Nested (key,value) map of arbitrary depth
 * @throws IOException IO exception
 */
public static Map<String, Object> parseYamlString(String yaml) throws IOException {
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    TypeReference<HashMap<String, Object>> typeRef = new TypeReference<HashMap<String, Object>>() {
    };
    return mapper.readValue(yaml, typeRef);
}
 
Example #8
Source File: Schema.java    From DataVec with Apache License 2.0 2 votes vote down vote up
/**
 * Serialize this schema to yaml
 * @return the yaml representation of this schema
 */
public String toYaml() {
    return toJacksonString(new YAMLFactory());
}
 
Example #9
Source File: Schema.java    From deeplearning4j with Apache License 2.0 2 votes vote down vote up
/**
 * Serialize this schema to yaml
 * @return the yaml representation of this schema
 */
public String toYaml() {
    return toJacksonString(new YAMLFactory());
}