use of io.quarkus.vertx.http.runtime.devmode.Json.JsonObjectBuilder in project quarkus by quarkusio.
the class ArcDevRecorder method createBeansHandler.
public Handler<RoutingContext> createBeansHandler() {
return new Handler<RoutingContext>() {
@Override
public void handle(RoutingContext ctx) {
ctx.response().putHeader("Content-Type", "application/json");
ArcContainerImpl container = ArcContainerImpl.instance();
List<InjectableBean<?>> beans = new ArrayList<>();
beans.addAll(container.getBeans());
beans.addAll(container.getInterceptors());
beans.addAll(container.getDecorators());
String kindParam = ctx.request().getParam("kind");
InjectableBean.Kind kind = kindParam != null ? InjectableBean.Kind.from(kindParam.toUpperCase()) : null;
String scopeEndsWith = ctx.request().getParam("scope");
String beanClassStartsWith = ctx.request().getParam("beanClass");
for (Iterator<InjectableBean<?>> it = beans.iterator(); it.hasNext(); ) {
InjectableBean<?> injectableBean = it.next();
if (kind != null && !kind.equals(injectableBean.getKind())) {
it.remove();
}
if (scopeEndsWith != null && !injectableBean.getScope().getName().endsWith(scopeEndsWith)) {
it.remove();
}
if (beanClassStartsWith != null && !injectableBean.getBeanClass().getName().startsWith(beanClassStartsWith)) {
it.remove();
}
}
JsonArrayBuilder array = Json.array();
for (InjectableBean<?> injectableBean : beans) {
JsonObjectBuilder bean = Json.object();
bean.put("id", injectableBean.getIdentifier());
bean.put("kind", injectableBean.getKind().toString());
bean.put("generatedClass", injectableBean.getClass().getName());
bean.put("beanClass", injectableBean.getBeanClass().getName());
JsonArrayBuilder types = Json.array();
for (Type beanType : injectableBean.getTypes()) {
types.add(beanType.getTypeName());
}
bean.put("types", types);
JsonArrayBuilder qualifiers = Json.array();
for (Annotation qualifier : injectableBean.getQualifiers()) {
if (qualifier.annotationType().equals(Any.class) || qualifier.annotationType().equals(Default.class)) {
qualifiers.add("@" + qualifier.annotationType().getSimpleName());
} else {
qualifiers.add(qualifier.toString());
}
}
bean.put("qualifiers", qualifiers);
bean.put("scope", injectableBean.getScope().getName());
if (injectableBean.getDeclaringBean() != null) {
bean.put("declaringBean", injectableBean.getDeclaringBean().getIdentifier());
}
if (injectableBean.getName() != null) {
bean.put("name", injectableBean.getName());
}
if (injectableBean.isAlternative()) {
bean.put("alternativePriority", injectableBean.getAlternativePriority());
}
if (injectableBean.isDefaultBean()) {
bean.put("isDefault", true);
}
array.add(bean);
}
ctx.response().end(array.build());
}
};
}
use of io.quarkus.vertx.http.runtime.devmode.Json.JsonObjectBuilder in project quarkus by quarkusio.
the class ArcDevRecorder method createObserversHandler.
public Handler<RoutingContext> createObserversHandler() {
return new Handler<RoutingContext>() {
@Override
public void handle(RoutingContext ctx) {
ctx.response().putHeader("Content-Type", "application/json");
ArcContainerImpl container = ArcContainerImpl.instance();
List<InjectableObserverMethod<?>> observers = container.getObservers();
JsonArrayBuilder array = Json.array();
for (InjectableObserverMethod<?> injectableObserver : observers) {
JsonObjectBuilder observer = Json.object();
observer.put("generatedClass", injectableObserver.getClass().getName());
observer.put("observedType", injectableObserver.getObservedType().getTypeName());
if (!injectableObserver.getObservedQualifiers().isEmpty()) {
JsonArrayBuilder qualifiers = Json.array();
for (Annotation qualifier : injectableObserver.getObservedQualifiers()) {
qualifiers.add(qualifier.toString());
}
observer.put("qualifiers", qualifiers);
}
observer.put("priority", injectableObserver.getPriority());
observer.put("reception", injectableObserver.getReception().toString());
observer.put("transactionPhase", injectableObserver.getTransactionPhase().toString());
observer.put("async", injectableObserver.isAsync());
if (injectableObserver.getDeclaringBeanIdentifier() != null) {
observer.put("declaringBean", injectableObserver.getDeclaringBeanIdentifier());
}
array.add(observer);
}
ctx.response().end(array.build());
}
};
}
use of io.quarkus.vertx.http.runtime.devmode.Json.JsonObjectBuilder in project quarkus by quarkusio.
the class JsonTest method testABitMoreComplexStructure.
@Test
public void testABitMoreComplexStructure() {
JsonObjectBuilder builder = Json.object().put("items", Json.array().add(1).add(2)).put("name", "Foo").put("parent", Json.object(true).put("name", "Martin").put("age", 100).put("active", true).put("children", Json.array(true).add(Json.object())));
assertFalse(builder.isEmpty());
assertEquals("{\"items\":[1,2],\"name\":\"Foo\",\"parent\":{\"name\":\"Martin\",\"age\":100,\"active\":true}}", builder.build());
}
use of io.quarkus.vertx.http.runtime.devmode.Json.JsonObjectBuilder in project quarkus by quarkusio.
the class JsonTest method testIgnoreEmptyBuilders.
@Test
public void testIgnoreEmptyBuilders() {
assertEquals("[true]", Json.array(true).add(true).add(Json.object(true).put("foo", Json.object())).build());
JsonObjectBuilder objectBuilder = Json.object();
JsonArrayBuilder arrayBuilder = Json.array().add(objectBuilder);
objectBuilder.put("foo", "bar");
assertEquals("[{\"foo\":\"bar\"}]", arrayBuilder.build());
}
use of io.quarkus.vertx.http.runtime.devmode.Json.JsonObjectBuilder in project quarkus by quarkusio.
the class ArcDevRecorder method createRemovedBeansHandler.
public Handler<RoutingContext> createRemovedBeansHandler(List<String[]> removedInterceptorsDecorators) {
return new Handler<RoutingContext>() {
@Override
public void handle(RoutingContext ctx) {
ArcContainerImpl container = ArcContainerImpl.instance();
ctx.response().putHeader("Content-Type", "application/json");
JsonArrayBuilder removed = Json.array();
for (RemovedBean removedBean : container.getRemovedBeans()) {
JsonObjectBuilder bean = Json.object();
bean.put("kind", removedBean.getKind().toString());
bean.put("description", removedBean.getDescription());
JsonArrayBuilder types = Json.array();
for (Type beanType : removedBean.getTypes()) {
types.add(beanType instanceof Class ? ((Class<?>) beanType).getName() : beanType.toString());
}
// java.lang.Object is always skipped
types.add(Object.class.getName());
bean.put("types", types);
JsonArrayBuilder qualifiers = Json.array();
for (Annotation qualifier : removedBean.getQualifiers()) {
if (qualifier.annotationType().equals(Any.class) || qualifier.annotationType().equals(Default.class)) {
qualifiers.add("@" + qualifier.annotationType().getSimpleName());
} else {
qualifiers.add(qualifier.toString());
}
}
bean.put("qualifiers", qualifiers);
removed.add(bean);
}
for (String[] interceptorDecorator : removedInterceptorsDecorators) {
JsonObjectBuilder bean = Json.object();
bean.put("kind", interceptorDecorator[0]);
bean.put("description", interceptorDecorator[1]);
removed.add(bean);
}
ctx.response().end(removed.build());
}
};
}
Aggregations