Type-safe record wrappers to serialize as XML Attributes
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 35/100
Línea de trabajo
Empieza por el ejemplo SerialDemo2 del issue, especialmente por XmlMapper.builder().build() y la llamada a mapper.writeValue. Investiga cómo se gestionan los componentes del record LocationID y Location cuando están marcados con @JacksonXmlProperty(isAttribute = true). Se considera terminado cuando los records serializan sus valores UUID como atributos XML con los nombres de elemento y atributo esperados.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Is your feature request related to a problem? Please describe.
The following example code uses a trivial wrapper record (LocationID) to allow some extra type-safety when working with elements declared in an existing schema:
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import java.io.IOException;
import java.util.Objects;
import java.util.UUID;
public final class SerialDemo2
{
private SerialDemo2()
{
}
record LocationID(UUID id) {
LocationID {
Objects.requireNonNull(id, "id");
}
}
@JacksonXmlRootElement(namespace = "urn:com.io7m.cardant.inventory:1")
record Location(
@JsonProperty(required = true)
@JacksonXmlProperty(isAttribute = true, localName = "id")
LocationID id,
@JsonProperty(required = false)
@JacksonXmlProperty(isAttribute = true, localName = "parent")
LocationID parent
) {
Location {
Objects.requireNonNull(id, "id");
}
}
public static void main(
final String[] args)
throws IOException
{
final var mapper =
XmlMapper.builder()
.build();
System.out.println("Expected: ");
System.out.println();
System.out.println("""
<Location xmlns="urn:com.io7m.cardant.inventory:1"
id="6e3f4213-db36-4ea3-91ba-1ce6917cbcbb"
parent="265f34b3-8c86-4a1f-b23a-bb104238bfc6"/>
""");
System.out.println("Received: ");
System.out.println();
mapper.writeValue(
System.out,
new Location(
new LocationID(UUID.randomUUID()),
new LocationID(UUID.randomUUID())
)
);
System.out.println();
}
}
The output of the program ends up as:
Expected:
<Location xmlns="urn:com.io7m.cardant.inventory:1"
id="6e3f4213-db36-4ea3-91ba-1ce6917cbcbb"
parent="265f34b3-8c86-4a1f-b23a-bb104238bfc6"/>
Received:
<Location xmlns="urn:com.io7m.cardant.inventory:1"><id xmlns=""><id>c09fb552-e36c-4213-b56a-7729cd5b7999</id></id><parent xmlns=""><id>58c399ae-0256-4dbd-a00e-0c1c01189559</id></parent></Location>
The desired output can be produced with the following definitions instead:
final class CA1LocationID
{
private final UUID id;
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
public CA1LocationID(
final UUID inId)
{
this.id = Objects.requireNonNull(inId, "id");
}
@JsonValue
@Override
public UUID id()
{
return this.id;
}
}
But it's slightly unfortunate that the definitions have to be declared in this way, because we lose a lot of the nice properties of record classes in the process.
Describe the solution you'd like
I'd like to be able to use records instead of POJOs in the above example.
Usage example
See above. 🙂
Additional context
See this thread on the mailing list: https://groups.google.com/d/msgid/jackson-user/20210911172814.62fd2925%40sunflower.int.arc7.info
- Lenguaje dominante
- Java
- Estrellas
- 636
- Forks
- 250
- Merge medio
- 7 h 10 min
- PR fusionados (30 d)
- 8
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de FasterXML/jackson-dataformat-xml
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
-
Dificultad 4/5 3-5 días Aptitud para principiantes 55/100
-
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
FasterXML/jackson-dataformat-xml#931 · 3 comentarios ·
-
XmlMapper with `FAIL_ON_UNKNOWN_PROPERTIES` fails on whitespace-only elementPosiblemente ocupada @arimu1 la tomó hace 89 días. Abiertoto-evaluate
Dificultad 3/5 1-2 días Aptitud para principiantes 68/100
-
3.x
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
FasterXML/jackson-dataformat-xml#787 · 1 comentario ·
Todos los issues de FasterXML/jackson-dataformat-xml
Issues similares
-
Cleanup: restore the interrupt flag in AiFailureAnalyzerPosiblemente ocupada @Rishankgupta08 la tomó hoy. Abiertogood first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
seleniumboot/selenium-boot#258 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
dense-analysis/ale#5181 ·
-
bug subsystem:agent-harness triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
ShaftHQ/SHAFT_ENGINE#8043 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
johanhaleby/occurrent#1505 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día