Class JacksonSerializerFactory
java.lang.Object
io.quarkus.resteasy.reactive.jackson.deployment.processor.JacksonCodeGenerator
io.quarkus.resteasy.reactive.jackson.deployment.processor.JacksonSerializerFactory
Generates an implementation of the Jackson's
StdSerializer for each class that needs to be serialized in json.
In this way the serialization process can be performed through the ad-hoc generate serializer and then without
any use of reflection. For instance for a pojo like this
public class Person {
private String firstName;
@JsonProperty("familyName")
private String lastName;
private int age;
@SecureField(rolesAllowed = "admin")
private Address address;
public Person() {
}
public Person(String firstName, String lastName, int age, Address address) {
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
this.address = address;
}
// getters and setters omitted
}
it generates the following StdSerializer implementation
public class Person$quarkusjacksonserializer extends StdSerializer {
static final String[] address_ROLES_ALLOWED = new String[] { "admin" };
public Person$quarkusjacksonserializer() {
super(Person.class);
}
public void serialize(Object var1, JsonGenerator var2, SerializerProvider var3) throws IOException {
Person var4 = (Person) var1;
var2.writeStartObject();
var2.writeFieldName(SerializedStrings$quarkusjacksonserializer.age);
int var5 = var4.getAge();
var2.writeNumber(var5);
var2.writeFieldName(SerializedStrings$quarkusjacksonserializer.firstName);
String var6 = var4.getFirstName();
var2.writeString(var6);
var2.writeFieldName(SerializedStrings$quarkusjacksonserializer.familyName);
String var7 = var4.getLastName();
var2.writeString(var7);
if (JacksonMapperUtil.includeSecureField(address_ROLES_ALLOWED)) {
var2.writeFieldName(SerializedStrings$quarkusjacksonserializer.address);
Address var9 = var4.getAddress();
JacksonSerializationUtils.serializePojo(var9, var2, var3);
}
var2.writeEndObject();
}
}
public class SerializedStrings$quarkusjacksonserializer {
static final SerializedString age = new SerializedString("age");
static final SerializedString firstName = new SerializedString("firstName");
static final SerializedString familyName = new SerializedString("familyName");
static final SerializedString address = new SerializedString("address");
}
Here, for performance reasons, the names of the fields to be serialized is stored as Jackson's SerializedStrings
in an external class, and reused for each serialization, thus avoiding executing the UTF-8 encoding of the same strings
at each serialization.
Note that in this case also the Address class has to be serialized in the same way, and then this factory triggers
the generation of a second StdSerializer also for it. More in general if during the generation of a serializer for a
given class it discovers a non-primitive field of another type for which a serializer hasn't been generated yet, this
factory enqueues a code generation also for that type. The same is valid for both arrays of that type, like
Address[], and collections, like List<Address>.-
Nested Class Summary
Nested classes/interfaces inherited from class io.quarkus.resteasy.reactive.jackson.deployment.processor.JacksonCodeGenerator
JacksonCodeGenerator.FieldKind, JacksonCodeGenerator.FieldSpecs -
Field Summary
Fields inherited from class io.quarkus.resteasy.reactive.jackson.deployment.processor.JacksonCodeGenerator
generatedClassBuildItemBuildProducer, generatedClassNames, jandexIndex, toBeGenerated -
Constructor Summary
ConstructorsConstructorDescriptionJacksonSerializerFactory(io.quarkus.deployment.annotations.BuildProducer<io.quarkus.deployment.builditem.GeneratedClassBuildItem> generatedClassBuildItemBuildProducer, org.jboss.jandex.IndexView jandexIndex) -
Method Summary
Modifier and TypeMethodDescriptioncreate(Collection<org.jboss.jandex.ClassInfo> classInfos) protected booleancreateSerializationMethod(org.jboss.jandex.ClassInfo classInfo, io.quarkus.gizmo.ClassCreator classCreator, String beanClassName) protected Stringprotected StringMethods inherited from class io.quarkus.resteasy.reactive.jackson.deployment.processor.JacksonCodeGenerator
classFields, classFields, classMethods, fieldSpecsFromField, fieldSpecsFromFieldParam, findConstructor, findMethod, getInterfacesNames, onSuperClass, registerTypeToBeGenerated, shouldGenerateCodeFor, ucFirst, vetoedClass
-
Constructor Details
-
JacksonSerializerFactory
public JacksonSerializerFactory(io.quarkus.deployment.annotations.BuildProducer<io.quarkus.deployment.builditem.GeneratedClassBuildItem> generatedClassBuildItemBuildProducer, org.jboss.jandex.IndexView jandexIndex)
-
-
Method Details
-
create
- Overrides:
createin classJacksonCodeGenerator
-
getSuperClassName
- Specified by:
getSuperClassNamein classJacksonCodeGenerator
-
getClassSuffix
- Specified by:
getClassSuffixin classJacksonCodeGenerator
-
createSerializationMethod
protected boolean createSerializationMethod(org.jboss.jandex.ClassInfo classInfo, io.quarkus.gizmo.ClassCreator classCreator, String beanClassName) - Specified by:
createSerializationMethodin classJacksonCodeGenerator
-