use of io.atlasmap.v2.Json in project atlasmap by atlasmap.
the class AtlasMappingService method loadMapping.
public AtlasMapping loadMapping(File file, AtlasMappingFormat format) throws AtlasValidationException {
try {
AtlasMapping atlasMapping;
switch(format) {
case XML:
StreamSource streamSource = new StreamSource(file);
atlasMapping = createUnmarshaller().unmarshal(streamSource, AtlasMapping.class).getValue();
break;
case JSON:
atlasMapping = jsonMapper.readValue(file, AtlasMapping.class);
break;
default:
throw new AtlasValidationException("Unsupported mapping format: " + format.value);
}
validate(atlasMapping);
return atlasMapping;
} catch (Exception e) {
throw new AtlasValidationException(e.getMessage(), e);
}
}
use of io.atlasmap.v2.Json in project atlasmap by atlasmap.
the class AtlasMappingService method loadMapping.
public AtlasMapping loadMapping(Reader reader, AtlasMappingFormat format) throws AtlasValidationException {
try {
AtlasMapping atlasMapping;
switch(format) {
case XML:
StreamSource streamSource = new StreamSource(reader);
atlasMapping = createUnmarshaller().unmarshal(streamSource, AtlasMapping.class).getValue();
break;
case JSON:
atlasMapping = jsonMapper.readValue(reader, AtlasMapping.class);
break;
default:
throw new AtlasValidationException("Unsupported mapping format: " + format.value);
}
validate(atlasMapping);
return atlasMapping;
} catch (Exception e) {
throw new AtlasValidationException(e.getMessage(), e);
}
}
use of io.atlasmap.v2.Json in project atlasmap by atlasmap.
the class SchemaInspectorTest method inspectJsonSchemaGeo.
// examples from json-schema.org
@Test
public void inspectJsonSchemaGeo() throws Exception {
final String schema = new String(Files.readAllBytes(Paths.get("src/test/resources/inspect/schema/geo.json")));
JsonDocument document = inspectionService.inspectJsonSchema(schema);
List<Field> fields = document.getFields().getField();
JsonField f = (JsonField) fields.get(0);
assertEquals("latitude", f.getName());
assertEquals("/latitude", f.getPath());
assertEquals(FieldType.NUMBER, f.getFieldType());
f = (JsonField) fields.get(1);
assertEquals("longitude", f.getName());
assertEquals("/longitude", f.getPath());
assertEquals(FieldType.NUMBER, f.getFieldType());
}
use of io.atlasmap.v2.Json in project atlasmap by atlasmap.
the class JavaToXMLJSONMarshallingTest method testCombineMappingDemarshaller.
@Test
public void testCombineMappingDemarshaller() throws Exception {
// this test is for AT-466: issue saving mappings in combine mode (parser
// complaining about strategy property)
// the json has been changed from what the UI was sending, now the "actions"
// property on the output field is "null" rather than "[]"
String filename = "src/test/resources/javaToXml/javaToXmlMapping-combine.json";
AtlasMapping uMapping = mapper.readValue(new File(filename), AtlasMapping.class);
assertNotNull(uMapping);
}
use of io.atlasmap.v2.Json in project syndesis-qe by syndesisio.
the class AtlasMapperGenerator method getAtlasMappingStep.
/**
* This method is used to generate the "AtlasMapping" - the atlasMapping contains list of specifications of
* dataSources and a list of specifications of dataMappings. Both these a must have for a complete and working
* AtlasMapping.
*
* @return step with the mapping defined
*/
public Step getAtlasMappingStep() {
processPrecedingSteps();
processFollowingStep();
AtlasMapping atlasMapping = new AtlasMapping();
atlasMapping.setMappings(new Mappings());
for (DataSource s : processSources()) {
atlasMapping.getDataSource().add(s);
}
atlasMapping.setName("REST." + UUID.randomUUID().toString().replaceAll("-", ""));
atlasMapping.setLookupTables(new LookupTables());
atlasMapping.setProperties(new Properties());
atlasMapping.getDataSource().add(processTarget());
atlasMapping.getMappings().getMapping().addAll(generateBaseMappings());
ObjectMapper mapper = new ObjectMapper();
mapper.enable(SerializationFeature.WRAP_ROOT_VALUE);
String mapperString = null;
try {
mapperString = mapper.writeValueAsString(atlasMapping);
log.debug(mapperString);
} catch (JsonProcessingException e) {
log.error("Unable to write mapper json as string", e);
}
return new Step.Builder().stepKind(StepKind.mapper).name(mapping.getStep().getName()).configuredProperties(TestUtils.map("atlasmapping", mapperString)).action(getMapperStepAction(followingStep.getStep().getAction().get().getInputDataShape().get())).id(UUID.randomUUID().toString()).build();
}
Aggregations