Example usage for com.fasterxml.jackson.dataformat.yaml YAMLFactory YAMLFactory

List of usage examples for com.fasterxml.jackson.dataformat.yaml YAMLFactory YAMLFactory

Introduction

In this page you can find the example usage for com.fasterxml.jackson.dataformat.yaml YAMLFactory YAMLFactory.

Prototype

public YAMLFactory() 

Source Link

Document

Default constructor used to create factory instances.

Usage

From source file:org.apache.myriad.MyriadModule.java

protected MyriadConfiguration generateMyriadConfiguration(String configFile) {
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());

    try {//  ww  w  .  j  a v  a 2 s  . co  m
        return mapper.readValue(Thread.currentThread().getContextClassLoader().getResource(configFile),
                MyriadConfiguration.class);
    } catch (IOException e) {
        LOGGER.error("The configFile {} could not be found", configFile);
        throw new IllegalArgumentException("The configFile cannot be found", e);
    }
}

From source file:com.github.fabioticconi.roguelite.systems.BootstrapSystem.java

public void loadBody(final String filename, final EntityEdit edit) throws IOException {
    final YAMLFactory factory = new YAMLFactory();
    final JsonParser parser = factory.createParser(new File(filename));

    int str = 0, agi = 0, con = 0, skin = 0, sight = 0;
    boolean herbivore = false, carnivore = false;

    parser.nextToken(); // START_OBJECT

    while (parser.nextToken() != null) {
        final String name = parser.getCurrentName();

        if (name == null)
            break;

        parser.nextToken(); // get in value

        System.out.println(name);

        if (name.equals("strength")) {
            str = parser.getIntValue();//from   www .  ja  va  2  s.  com
            edit.create(Strength.class).value = Util.ensureRange(str, -2, 2);
        } else if (name.equals("agility")) {
            agi = parser.getIntValue();
            edit.create(Agility.class).value = Util.ensureRange(agi, -2, 2);
        } else if (name.equals("constitution")) {
            con = parser.getIntValue();
            edit.create(Constitution.class).value = Util.ensureRange(con, -2, 2);
        } else if (name.equals("skin")) {
            skin = parser.getIntValue();
            edit.create(Skin.class).value = Util.ensureRange(skin, -2, 2);
        } else if (name.equals("sight")) {
            sight = parser.getIntValue();
            edit.create(Sight.class).value = Util.ensureRange(sight, 1, 18);
        } else if (name.equals("herbivore")) {
            herbivore = parser.getBooleanValue();

            if (herbivore)
                edit.create(Herbivore.class);
        } else if (name.equals("carnivore")) {
            carnivore = parser.getBooleanValue();

            if (carnivore)
                edit.create(Carnivore.class);
        }
    }

    // TODO check if neither herbivore nor carnivore? player is currently as such, for testing

    // Secondary Attributes
    final int size = Math.round((con - agi) / 2f);
    edit.create(Size.class).value = size;
    edit.create(Stamina.class).value = 5 + str + con;
    edit.create(Speed.class).value = (con - str - agi + 6) / 12f;

    // Tertiary Attributes
    edit.create(Hunger.class).value = (size / 2f) + 2f;
}

From source file:org.restlet.ext.jackson.JacksonRepresentation.java

/**
 * Creates a Jackson object mapper based on a media type. It supports JSON,
 * JSON Smile, XML, YAML and CSV./*from  ww  w  .j ava2 s . c  o m*/
 * 
 * @return The Jackson object mapper.
 */
protected ObjectMapper createObjectMapper() {
    ObjectMapper result = null;

    if (MediaType.APPLICATION_JSON.isCompatible(getMediaType())) {
        JsonFactory jsonFactory = new JsonFactory();
        jsonFactory.configure(Feature.AUTO_CLOSE_TARGET, false);
        result = new ObjectMapper(jsonFactory);
    } else if (MediaType.APPLICATION_JSON_SMILE.isCompatible(getMediaType())) {
        SmileFactory smileFactory = new SmileFactory();
        smileFactory.configure(Feature.AUTO_CLOSE_TARGET, false);
        result = new ObjectMapper(smileFactory);
        // [ifndef android]
    } else if (MediaType.APPLICATION_XML.isCompatible(getMediaType())
            || MediaType.TEXT_XML.isCompatible(getMediaType())) {
        javax.xml.stream.XMLInputFactory xif = XmlFactoryProvider.newInputFactory();
        xif.setProperty(javax.xml.stream.XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES,
                isExpandingEntityRefs());
        xif.setProperty(javax.xml.stream.XMLInputFactory.SUPPORT_DTD, isExpandingEntityRefs());
        xif.setProperty(javax.xml.stream.XMLInputFactory.IS_VALIDATING, isValidatingDtd());
        javax.xml.stream.XMLOutputFactory xof = XmlFactoryProvider.newOutputFactory();
        XmlFactory xmlFactory = new XmlFactory(xif, xof);
        xmlFactory.configure(Feature.AUTO_CLOSE_TARGET, false);
        result = new XmlMapper(xmlFactory);
        // [enddef]
    } else if (MediaType.APPLICATION_YAML.isCompatible(getMediaType())
            || MediaType.TEXT_YAML.isCompatible(getMediaType())) {
        YAMLFactory yamlFactory = new YAMLFactory();
        yamlFactory.configure(Feature.AUTO_CLOSE_TARGET, false);
        result = new ObjectMapper(yamlFactory);
    } else if (MediaType.TEXT_CSV.isCompatible(getMediaType())) {
        CsvFactory csvFactory = new CsvFactory();
        csvFactory.configure(Feature.AUTO_CLOSE_TARGET, false);
        result = new CsvMapper(csvFactory);
    } else {
        JsonFactory jsonFactory = new JsonFactory();
        jsonFactory.configure(Feature.AUTO_CLOSE_TARGET, false);
        result = new ObjectMapper(jsonFactory);
    }

    return result;
}

From source file:com.exalttech.trex.util.TrafficProfile.java

/**
 * @param trafficProfileArray//from   w  w w .j a  v  a  2 s  .c  o m
 *
 * @return Converts Traffic Profile to Yaml String
 * @throws JsonProcessingException
 *
 */
public String convertTrafficProfileToYaml(Profile[] trafficProfileArray) throws JsonProcessingException {
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    return mapper.writeValueAsString(trafficProfileArray);
}

From source file:com.exalttech.trex.util.TrafficProfile.java

/**
 * @param trafficProfileArray/*from ww w  .j  av  a 2  s.c o  m*/
 * @param fileName
 *
 * @return Converts Traffic Profile to Yaml String
 * @throws JsonProcessingException
 *
 */
public File convertTrafficProfileToYamlFile(Profile[] trafficProfileArray, String fileName) throws IOException {
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    String localFileName = FileManager.getProfilesFilePath() + fileName;
    File yamlFile = new File(localFileName);
    mapper.writeValue(yamlFile, trafficProfileArray);
    return yamlFile;
}

From source file:com.spotify.ffwd.AgentCore.java

private AgentConfig readConfig(Injector early) throws IOException {
    final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    final SimpleModule module = early
            .getInstance(Key.get(SimpleModule.class, Names.named("application/yaml+config")));

    mapper.registerModule(module);//  w w w .j  av  a  2s . c om

    try (final InputStream input = Files.newInputStream(this.config)) {
        return mapper.readValue(input, AgentConfig.class);
    } catch (JsonParseException e) {
        throw new IOException("Failed to parse configuration", e);
    }
}

From source file:com.nextdoor.bender.config.BenderConfig.java

public static ObjectMapper getObjectMapper(String filename) {
    String extension = FilenameUtils.getExtension(filename);
    ObjectMapper mapper = null;//from   w  ww.  j  a v  a 2 s  .c om
    switch (extension) {
    case "yaml":
        mapper = new ObjectMapper(new YAMLFactory());
        break;
    default:
        mapper = new ObjectMapper();
    }

    mapper.registerSubtypes(BenderConfig.subtypes);

    return mapper;
}

From source file:io.fabric8.jenkins.openshiftsync.OpenShiftUtils.java

public static String dumpWithoutRuntimeStateAsYaml(HasMetadata obj) throws JsonProcessingException {
    ObjectMapper statelessMapper = new ObjectMapper(new YAMLFactory());
    statelessMapper.addMixInAnnotations(ObjectMeta.class, ObjectMetaMixIn.class);
    statelessMapper.addMixInAnnotations(ReplicationController.class, StatelessReplicationControllerMixIn.class);
    return statelessMapper.writeValueAsString(obj);
}

From source file:portal.api.osm.client.OSMClient.java

/**
 * @param aNSDid//from  w  w  w .ja va  2s. c  o m
 * @return
 */
public Nsd getNSDbyID(String aNSDid) {

    String response = getOSMResponse(BASE_SERVICE_URL + "/nsd-catalog/nsd/" + aNSDid);

    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());

    try {

        JsonNode tr = mapper.readTree(response).findValue("nsd:nsd"); // needs a massage
        if (tr == null) {
            tr = mapper.readTree(response).findValue("nsd");
        }
        tr = tr.get(0);
        String s = tr.toString();
        s = s.replaceAll("vnfd:", ""); // some yaml files contain nsd: prefix in every key which is not common in
        // json

        Nsd nsd = mapper.readValue(s, Nsd.class);

        return nsd;

    } catch (IllegalStateException | IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return null;
}

From source file:io.fabric8.maven.core.util.KubernetesResourceUtil.java

private static Map<String, Object> readFragment(File file, String ext) throws IOException {
    ObjectMapper mapper = new ObjectMapper("json".equals(ext) ? new JsonFactory() : new YAMLFactory());
    TypeReference<HashMap<String, Object>> typeRef = new TypeReference<HashMap<String, Object>>() {
    };/* w w  w .j a v a  2 s. com*/
    try {
        Map<String, Object> ret = mapper.readValue(file, typeRef);
        return ret != null ? ret : new HashMap<String, Object>();
    } catch (JsonProcessingException e) {
        throw new JsonMappingException(String.format("[%s] %s", file, e.getMessage()), e.getLocation(), e);
    }
}