Java Code Examples for com.fasterxml.jackson.dataformat.yaml.YAMLMapper#readValue()
The following examples show how to use
com.fasterxml.jackson.dataformat.yaml.YAMLMapper#readValue() .
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: PodlockParser.java From synopsys-detect with Apache License 2.0 | 6 votes |
public DependencyGraph extractDependencyGraph(final String podLockText) throws IOException, MissingExternalIdException { final LazyExternalIdDependencyGraphBuilder lazyBuilder = new LazyExternalIdDependencyGraphBuilder(); final YAMLMapper mapper = new YAMLMapper(); final PodfileLock podfileLock = mapper.readValue(podLockText, PodfileLock.class); final Map<DependencyId, Forge> forgeOverrides = createForgeOverrideMap(podfileLock); for (final Pod pod : podfileLock.getPods()) { logger.trace(String.format("Processing pod %s", pod.getName())); processPod(pod, forgeOverrides, lazyBuilder); } for (final Pod dependency : podfileLock.getDependencies()) { logger.trace(String.format("Processing pod dependency from pod lock file %s", dependency.getName())); final String podText = dependency.getName(); final Optional<DependencyId> dependencyId = parseDependencyId(podText); dependencyId.ifPresent(lazyBuilder::addChildToRoot); } logger.trace("Attempting to build the dependency graph."); final DependencyGraph dependencyGraph = lazyBuilder.build(); logger.trace("Completed the dependency graph."); return dependencyGraph; }
Example 2
Source File: ClassWithInterfaceFieldsRegistry.java From istio-java-api with Apache License 2.0 | 6 votes |
Object deserialize(JsonNode node, String fieldName, Class targetClass, DeserializationContext ctxt) throws IOException { final String type = getFieldClassFQN(targetClass, valueType); try { // load class of the field final Class<?> fieldClass = Thread.currentThread().getContextClassLoader().loadClass(type); // create a map type matching the type of the field from the mapping information final YAMLMapper codec = (YAMLMapper) ctxt.getParser().getCodec(); MapType mapType = codec.getTypeFactory().constructMapType(Map.class, String.class, fieldClass); // get a parser taking the current value as root final JsonParser traverse = node.get(fieldName).traverse(codec); // and use it to deserialize the subtree as the map type we just created return codec.readValue(traverse, mapType); } catch (ClassNotFoundException e) { throw new RuntimeException("Unsupported type '" + type + "' for field '" + fieldName + "' on '" + targetClass.getName() + "' class. Full type was " + this, e); } }
Example 3
Source File: PodlockParser.java From hub-detect with Apache License 2.0 | 6 votes |
public DependencyGraph extractDependencyGraph(final String podLockText) throws IOException { final LazyExternalIdDependencyGraphBuilder lazyBuilder = new LazyExternalIdDependencyGraphBuilder(); final YAMLMapper mapper = new YAMLMapper(); final PodfileLock podfileLock = mapper.readValue(podLockText, PodfileLock.class); final Map<DependencyId, Forge> forgeOverrides = createForgeOverrideMap(podfileLock); for (final Pod pod : podfileLock.pods) { logger.trace(String.format("Processing pod %s", pod.name)); processPod(pod, forgeOverrides, lazyBuilder); } for (final Pod dependency : podfileLock.dependencies) { logger.trace(String.format("Processing pod dependency from pod lock file %s", dependency.name)); final String podText = dependency.name; final Optional<DependencyId> dependencyId = parseDependencyId(podText); if (dependencyId.isPresent()) { lazyBuilder.addChildToRoot(dependencyId.get()); } } logger.trace("Attempting to build the dependency graph."); final DependencyGraph dependencyGraph = lazyBuilder.build(); logger.trace("Completed the dependency graph."); return dependencyGraph; }
Example 4
Source File: LoadPayment.java From XS2A-Sandbox with Apache License 2.0 | 5 votes |
public static PaymentCase loadPayment(Class<?> location, String file, YAMLMapper ymlMapper) { InputStream stream = location.getResourceAsStream(file); try { return ymlMapper.readValue(stream, PaymentCase.class); } catch (IOException e) { throw new IllegalStateException(e); } }
Example 5
Source File: LoadPayment.java From XS2A-Sandbox with Apache License 2.0 | 5 votes |
public static PaymentCase loadPayment(Class<?> location, String file, YAMLMapper ymlMapper) { InputStream stream = location.getResourceAsStream(file); try { return ymlMapper.readValue(stream, PaymentCase.class); } catch (IOException e) { throw new IllegalStateException(e); } }
Example 6
Source File: KafkaVersion.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
/** * Parse the version information present in the {@code /kafka-versions} classpath resource. * @param reader A reader for the Kafka version file. * @param mapOfVersions A map to add the versions to. * @return The configured default Kafka version. * @throws IllegalArgumentException If there are duplicate versions listed in the versions file or more than one * version is listed as the default. * @throws RuntimeException If no default version was set. * @throws IOException If the Kafka versions file cannot be read. */ public static KafkaVersion parseKafkaVersions(Reader reader, Map<String, KafkaVersion> mapOfVersions) throws IOException, IllegalArgumentException { YAMLMapper mapper = new YAMLMapper(); List<KafkaVersion> kafkaVersions = mapper.readValue(reader, new TypeReference<List<KafkaVersion>>() { }); KafkaVersion defaultVersion = null; for (KafkaVersion kafkaVersion: kafkaVersions) { if (mapOfVersions.put(kafkaVersion.version, kafkaVersion) != null) { throw new IllegalArgumentException("Duplicate version (" + kafkaVersion.version + ") listed in kafka-versions file"); } if (kafkaVersion.isDefault) { if (defaultVersion == null) { defaultVersion = kafkaVersion; } else { throw new IllegalArgumentException( "Multiple Kafka versions (" + defaultVersion.version() + " and " + kafkaVersion.version() + ") are set as default"); } } } if (defaultVersion != null) { return defaultVersion; } else { throw new RuntimeException("No Kafka version was configured as the default"); } }
Example 7
Source File: TestKafkaVersion.java From strimzi-kafka-operator with Apache License 2.0 | 4 votes |
/** * Parse the version information present in the {@code /kafka-versions} classpath resource and return a sorted list * from earliest to latest kafka version. * * @return A list of the kafka versions listed in the kafka-versions.yaml file */ private static List<TestKafkaVersion> parseKafkaVersions() throws IOException { YAMLMapper mapper = new YAMLMapper(); Reader versionsFileReader = new InputStreamReader( TestKafkaVersion.class.getResourceAsStream("/kafka-versions.yaml"), StandardCharsets.UTF_8); List<TestKafkaVersion> testKafkaVersions = mapper.readValue(versionsFileReader, new TypeReference<List<TestKafkaVersion>>() { }); Collections.sort(testKafkaVersions); return testKafkaVersions; }