use of org.apache.johnzon.mapper.MapperBuilder in project camel by apache.
the class JohnzonDataFormat method doStart.
@Override
protected void doStart() throws Exception {
if (objectMapper == null) {
MapperBuilder builder = new MapperBuilder();
builder.setPretty(pretty);
builder.setSkipNull(skipNull);
builder.setSkipEmptyArray(skipEmptyArray);
if (ObjectHelper.isNotEmpty(encoding)) {
builder.setEncoding(encoding);
}
if (ObjectHelper.isNotEmpty(attributeOrder)) {
builder.setAttributeOrder(attributeOrder);
}
objectMapper = new MapperBuilder().build();
}
}
use of org.apache.johnzon.mapper.MapperBuilder in project component-runtime by Talend.
the class Generator method generatedConditions.
private static void generatedConditions(final File generatedDir) throws Exception {
final File file = new File(generatedDir, "generated_conditions.adoc");
try (final PrintStream stream = new PrintStream(new WriteIfDifferentStream(file))) {
stream.println("");
stream.println("[role=\"table-striped table-hover table-ordered\",options=\"header,autowidth\"]");
stream.println("|====");
stream.println("|API|Name|Description|Metadata Sample");
final File api = jarLocation(Condition.class);
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
final ConditionParameterEnricher enricher = new ConditionParameterEnricher();
final Mapper mapper = new MapperBuilder().build();
final AnnotationFinder finder = new AnnotationFinder(api.isDirectory() ? new FileArchive(loader, api) : new JarArchive(loader, api.toURI().toURL()));
finder.findAnnotatedClasses(Condition.class).stream().sorted(comparing(Class::getName)).forEach(type -> stream.println("|@" + type.getName() + "|" + type.getAnnotation(Condition.class).value() + "|" + extractDoc(type) + "|" + mapper.writeObjectAsString(enricher.onParameterAnnotation("test", String.class, generateAnnotation(type))).replace("tcomp::", "")));
stream.println("|====");
stream.println();
}
}
use of org.apache.johnzon.mapper.MapperBuilder in project component-runtime by Talend.
the class Generator method generatedTypes.
private static void generatedTypes(final File generatedDir) throws Exception {
final File file = new File(generatedDir, "generated_configuration-types.adoc");
try (final PrintStream stream = new PrintStream(new WriteIfDifferentStream(file))) {
stream.println("");
stream.println("[role=\"table-striped table-hover table-ordered\",options=\"header,autowidth\"]");
stream.println("|====");
stream.println("|API|Type|Description|Metadata sample");
final File api = jarLocation(ConfigurationType.class);
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
final ConfigurationTypeParameterEnricher enricher = new ConfigurationTypeParameterEnricher();
final Mapper mapper = new MapperBuilder().build();
final AnnotationFinder finder = new AnnotationFinder(api.isDirectory() ? new FileArchive(loader, api) : new JarArchive(loader, api.toURI().toURL()));
finder.findAnnotatedClasses(ConfigurationType.class).stream().sorted(comparing(Class::getName)).forEach(type -> stream.println("|" + type.getName() + "|" + type.getAnnotation(ConfigurationType.class).value() + "|" + extractDoc(type) + "|" + mapper.writeObjectAsString(enricher.onParameterAnnotation("value", String.class, generateAnnotation(type)))));
stream.println("|====");
stream.println();
}
}
use of org.apache.johnzon.mapper.MapperBuilder in project component-runtime by Talend.
the class Generator method sample.
private static String sample(final Class<?> returnedType) {
if (returnedType == Values.class) {
final Values list = new Values();
list.setItems(new ArrayList<>());
final Values.Item item = new Values.Item();
item.setId("value");
item.setLabel("label");
list.getItems().add(item);
return new MapperBuilder().setPretty(false).build().writeObjectAsString(list);
}
if (returnedType == HealthCheckStatus.class) {
final HealthCheckStatus status = new HealthCheckStatus();
status.setStatus(HealthCheckStatus.Status.KO);
status.setComment("Something went wrong");
return new MapperBuilder().setPretty(false).build().writeObjectAsString(status);
}
if (returnedType == Schema.class) {
final Schema.Entry entry = new Schema.Entry();
entry.setName("column1");
entry.setType(Type.STRING);
final Schema schema = new Schema();
schema.setEntries(new ArrayList<>());
schema.getEntries().add(entry);
return new MapperBuilder().setPretty(false).build().writeObjectAsString(schema);
}
if (returnedType == ValidationResult.class) {
final ValidationResult status = new ValidationResult();
status.setStatus(ValidationResult.Status.KO);
status.setComment("Something went wrong");
return new MapperBuilder().setPretty(false).build().writeObjectAsString(status);
}
return "{\n" + Stream.of(returnedType.getDeclaredFields()).map(f -> " \"" + f.getName() + "\": " + createSample(f.getType())).collect(joining("\n")) + "\n}";
}
use of org.apache.johnzon.mapper.MapperBuilder in project component-runtime by Talend.
the class Generator method generatedConstraints.
private static void generatedConstraints(final File generatedDir) throws Exception {
final File file = new File(generatedDir, "generated_constraints.adoc");
try (final PrintStream stream = new PrintStream(new WriteIfDifferentStream(file))) {
stream.println("");
stream.println("[role=\"table-striped table-hover table-ordered\",options=\"header,autowidth\"]");
stream.println("|====");
stream.println("|API|Name|Parameter Type|Description|Supported Types|Metadata sample");
final File api = jarLocation(Validation.class);
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
final AnnotationFinder finder = new AnnotationFinder(api.isDirectory() ? new FileArchive(loader, api) : new JarArchive(loader, api.toURI().toURL()));
final ValidationParameterEnricher enricher = new ValidationParameterEnricher();
final Mapper mapper = new MapperBuilder().build();
Stream.concat(finder.findAnnotatedClasses(Validation.class).stream().map(validation -> {
final Validation val = validation.getAnnotation(Validation.class);
return createConstraint(validation, val);
}), finder.findAnnotatedClasses(Validations.class).stream().flatMap(validations -> Stream.of(validations.getAnnotation(Validations.class).value()).map(validation -> createConstraint(validations, validation)))).sorted((o1, o2) -> {
final int types = Stream.of(o1.types).map(Class::getName).collect(joining("/")).compareTo(Stream.of(o2.types).map(Class::getName).collect(joining("/")));
if (types == 0) {
return o1.name.compareTo(o2.name);
}
return types;
}).forEach(constraint -> stream.println("|@" + constraint.marker.getName() + "|" + constraint.name + "|" + sanitizeType(constraint.paramType) + "|" + constraint.description + "|" + Stream.of(constraint.types).map(Class::getName).map(Generator::sanitizeType).collect(joining(", ")) + "|" + mapper.writeObjectAsString(enricher.onParameterAnnotation("test", constraint.types[0], generateAnnotation(constraint.marker))).replace("tcomp::", "")));
stream.println("|====");
stream.println();
}
}
Aggregations