Type-safe record wrappers to serialize as XML Attributes
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Bắt đầu với ví dụ SerialDemo2 trong issue, đặc biệt là XmlMapper.builder().build() và lệnh gọi mapper.writeValue. Điều tra cách các thành phần record LocationID và Location được xử lý khi được đánh dấu bằng @JacksonXmlProperty(isAttribute = true). Công việc được xem là hoàn tất khi các record tuần tự hóa các giá trị UUID của chúng thành các thuộc tính XML với tên phần tử và thuộc tính như mong đợi.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- Java
- Star
- 636
- Fork
- 250
- Merge trung bình
- 7 giờ 10 phút
- Pull request đã merge (30 ngày)
- 8
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của FasterXML/jackson-dataformat-xml
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
FasterXML/jackson-dataformat-xml#931 · 3 bình luận ·
-
XmlMapper with `FAIL_ON_UNKNOWN_PROPERTIES` fails on whitespace-only elementCó thể đã có người làm @arimu1 đã nhận 89 ngày trước. Đang mởto-evaluate
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
-
3.x
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
FasterXML/jackson-dataformat-xml#787 · 1 bình luận ·
Tất cả issue của FasterXML/jackson-dataformat-xml
Issue tương tự
-
Cleanup: restore the interrupt flag in AiFailureAnalyzerCó thể đã có người làm @Rishankgupta08 đã nhận hôm nay. Đang mởgood first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
seleniumboot/selenium-boot#258 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
dense-analysis/ale#5181 ·
-
bug subsystem:agent-harness triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
ShaftHQ/SHAFT_ENGINE#8043 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
johanhaleby/occurrent#1505 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày