Skip to content

Commit b91e542

Browse files
committed
JAMES-2813 DTO <-> domain object must be a bijection for jackson to work
Reference: FasterXML/jackson-databind#2515
1 parent bb85dd9 commit b91e542

File tree

2 files changed

+94
-30
lines changed

2 files changed

+94
-30
lines changed

Diff for: mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReprocessingContextInformationDTO.java

+35-11
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,27 @@ public List<Long> getUids() {
5858
}
5959

6060
public static class ReprocessingContextInformationForErrorRecoveryIndexationTask extends ReprocessingContextInformation {
61-
public static final AdditionalInformationDTOModule<ReprocessingContextInformationForErrorRecoveryIndexationTask, ReprocessingContextInformationDTO> serializationModule(MailboxId.Factory mailboxIdFactory) {
61+
62+
public static class DTO extends ReprocessingContextInformationDTO {
63+
64+
DTO(@JsonProperty("type") String type,
65+
@JsonProperty("successfullyReprocessedMailCount") int successfullyReprocessedMailCount,
66+
@JsonProperty("failedReprocessedMailCount") int failedReprocessedMailCount,
67+
@JsonProperty("failures") List<ReindexingFailureDTO> failures,
68+
@JsonProperty("timestamp") Instant timestamp) {
69+
super(type, successfullyReprocessedMailCount, failedReprocessedMailCount, failures, timestamp);
70+
}
71+
}
72+
73+
public static final AdditionalInformationDTOModule<ReprocessingContextInformationForErrorRecoveryIndexationTask, DTO> serializationModule(MailboxId.Factory mailboxIdFactory) {
6274
return DTOModule.forDomainObject(ReprocessingContextInformationForErrorRecoveryIndexationTask.class)
63-
.convertToDTO(ReprocessingContextInformationDTO.class)
75+
.convertToDTO(DTO.class)
6476
.toDomainObjectConverter(dto -> new ReprocessingContextInformationForErrorRecoveryIndexationTask(
6577
dto.successfullyReprocessedMailCount,
6678
dto.failedReprocessedMailCount,
6779
deserializeFailures(mailboxIdFactory, dto.failures),
6880
dto.getTimestamp()))
69-
.toDTOConverter((details, type) -> new ReprocessingContextInformationDTO(
81+
.toDTOConverter((details, type) -> new DTO(
7082
type,
7183
details.getSuccessfullyReprocessedMailCount(),
7284
details.getFailedReprocessedMailCount(),
@@ -82,11 +94,23 @@ public static final AdditionalInformationDTOModule<ReprocessingContextInformatio
8294
}
8395

8496
public static class ReprocessingContextInformationForFullReindexingTask extends ReprocessingContextInformation {
85-
public static final AdditionalInformationDTOModule<ReprocessingContextInformationForFullReindexingTask, ReprocessingContextInformationDTO> serializationModule(MailboxId.Factory mailboxIdFactory) {
97+
98+
public static class DTO extends ReprocessingContextInformationDTO {
99+
100+
DTO(@JsonProperty("type") String type,
101+
@JsonProperty("successfullyReprocessedMailCount") int successfullyReprocessedMailCount,
102+
@JsonProperty("failedReprocessedMailCount") int failedReprocessedMailCount,
103+
@JsonProperty("failures") List<ReindexingFailureDTO> failures,
104+
@JsonProperty("timestamp") Instant timestamp) {
105+
super(type, successfullyReprocessedMailCount, failedReprocessedMailCount, failures, timestamp);
106+
}
107+
}
108+
109+
public static final AdditionalInformationDTOModule<ReprocessingContextInformationForFullReindexingTask, DTO> serializationModule(MailboxId.Factory mailboxIdFactory) {
86110
return DTOModule.forDomainObject(ReprocessingContextInformationForFullReindexingTask.class)
87-
.convertToDTO(ReprocessingContextInformationDTO.class)
111+
.convertToDTO(DTO.class)
88112
.toDomainObjectConverter(dto -> new ReprocessingContextInformationForFullReindexingTask(dto.successfullyReprocessedMailCount, dto.failedReprocessedMailCount, deserializeFailures(mailboxIdFactory, dto.failures), dto.getTimestamp()))
89-
.toDTOConverter((details, type) -> new ReprocessingContextInformationDTO(
113+
.toDTOConverter((details, type) -> new DTO(
90114
type,
91115
details.getSuccessfullyReprocessedMailCount(),
92116
details.getFailedReprocessedMailCount(),
@@ -144,11 +168,11 @@ private static ImmutableList<Long> extractMessageUidsFromFailure(Map.Entry<Mailb
144168
.collect(Guavate.toImmutableList());
145169
}
146170

147-
private final String type;
148-
private final int successfullyReprocessedMailCount;
149-
private final int failedReprocessedMailCount;
150-
private final List<ReindexingFailureDTO> failures;
151-
private final Instant timestamp;
171+
protected final String type;
172+
protected final int successfullyReprocessedMailCount;
173+
protected final int failedReprocessedMailCount;
174+
protected final List<ReindexingFailureDTO> failures;
175+
protected final Instant timestamp;
152176

153177

154178
ReprocessingContextInformationDTO(@JsonProperty("type") String type,

Diff for: server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/EventDeadLettersRedeliveryTaskAdditionalInformationDTO.java

+59-19
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,29 @@
1414

1515
public class EventDeadLettersRedeliveryTaskAdditionalInformationDTO implements AdditionalInformationDTO {
1616
public static class EventDeadLettersRedeliveryTaskAdditionalInformationForAll extends EventDeadLettersRedeliveryTaskAdditionalInformation {
17-
public static final AdditionalInformationDTOModule<EventDeadLettersRedeliveryTaskAdditionalInformationForAll, EventDeadLettersRedeliveryTaskAdditionalInformationDTO> MODULE =
17+
18+
public static class DTO extends EventDeadLettersRedeliveryTaskAdditionalInformationDTO {
19+
public DTO(@JsonProperty("type") String type,
20+
@JsonProperty("successfulRedeliveriesCount") long successfulRedeliveriesCount,
21+
@JsonProperty("failedRedeliveriesCount") long failedRedeliveriesCount,
22+
@JsonProperty("group") Optional<String> group,
23+
@JsonProperty("insertionId") Optional<String> insertionId,
24+
@JsonProperty("timestamp") Instant timestamp) {
25+
super(type, successfulRedeliveriesCount, failedRedeliveriesCount, group,insertionId, timestamp);
26+
}
27+
}
28+
29+
public static final AdditionalInformationDTOModule<EventDeadLettersRedeliveryTaskAdditionalInformationForAll, DTO> MODULE =
1830
DTOModule
1931
.forDomainObject(EventDeadLettersRedeliveryTaskAdditionalInformationForAll.class)
20-
.convertToDTO(EventDeadLettersRedeliveryTaskAdditionalInformationDTO.class)
32+
.convertToDTO(DTO.class)
2133
.toDomainObjectConverter(EventDeadLettersRedeliveryTaskAdditionalInformationDTO::fromAll)
22-
.toDTOConverter(EventDeadLettersRedeliveryTaskAdditionalInformationDTO::toDTO)
34+
.toDTOConverter((domainObject, typeName) -> new DTO(typeName,
35+
domainObject.getSuccessfulRedeliveriesCount(),
36+
domainObject.getFailedRedeliveriesCount(),
37+
domainObject.getGroup(),
38+
domainObject.getInsertionId(),
39+
domainObject.timestamp()))
2340
.typeName(EventDeadLettersRedeliverAllTask.TYPE.asString())
2441
.withFactory(AdditionalInformationDTOModule::new);
2542

@@ -30,12 +47,29 @@ public static class EventDeadLettersRedeliveryTaskAdditionalInformationForAll ex
3047
}
3148

3249
public static class EventDeadLettersRedeliveryTaskAdditionalInformationForGroup extends EventDeadLettersRedeliveryTaskAdditionalInformation {
33-
public static final AdditionalInformationDTOModule<EventDeadLettersRedeliveryTaskAdditionalInformationForGroup, EventDeadLettersRedeliveryTaskAdditionalInformationDTO> MODULE =
50+
51+
public static class DTO extends EventDeadLettersRedeliveryTaskAdditionalInformationDTO {
52+
public DTO(@JsonProperty("type") String type,
53+
@JsonProperty("successfulRedeliveriesCount") long successfulRedeliveriesCount,
54+
@JsonProperty("failedRedeliveriesCount") long failedRedeliveriesCount,
55+
@JsonProperty("group") Optional<String> group,
56+
@JsonProperty("insertionId") Optional<String> insertionId,
57+
@JsonProperty("timestamp") Instant timestamp) {
58+
super(type, successfulRedeliveriesCount, failedRedeliveriesCount, group,insertionId, timestamp);
59+
}
60+
}
61+
62+
public static final AdditionalInformationDTOModule<EventDeadLettersRedeliveryTaskAdditionalInformationForGroup, DTO> MODULE =
3463
DTOModule
3564
.forDomainObject(EventDeadLettersRedeliveryTaskAdditionalInformationForGroup.class)
36-
.convertToDTO(EventDeadLettersRedeliveryTaskAdditionalInformationDTO.class)
65+
.convertToDTO(DTO.class)
3766
.toDomainObjectConverter(EventDeadLettersRedeliveryTaskAdditionalInformationDTO::fromGroup)
38-
.toDTOConverter(EventDeadLettersRedeliveryTaskAdditionalInformationDTO::toDTO)
67+
.toDTOConverter((domainObject, typeName) -> new DTO(typeName,
68+
domainObject.getSuccessfulRedeliveriesCount(),
69+
domainObject.getFailedRedeliveriesCount(),
70+
domainObject.getGroup(),
71+
domainObject.getInsertionId(),
72+
domainObject.timestamp()))
3973
.typeName(EventDeadLettersRedeliverGroupTask.TYPE.asString())
4074
.withFactory(AdditionalInformationDTOModule::new);
4175

@@ -46,12 +80,28 @@ public static class EventDeadLettersRedeliveryTaskAdditionalInformationForGroup
4680
}
4781

4882
public static class EventDeadLettersRedeliveryTaskAdditionalInformationForOne extends EventDeadLettersRedeliveryTaskAdditionalInformation {
49-
public static final AdditionalInformationDTOModule<EventDeadLettersRedeliveryTaskAdditionalInformationForOne, EventDeadLettersRedeliveryTaskAdditionalInformationDTO> MODULE =
83+
public static class DTO extends EventDeadLettersRedeliveryTaskAdditionalInformationDTO {
84+
public DTO(@JsonProperty("type") String type,
85+
@JsonProperty("successfulRedeliveriesCount") long successfulRedeliveriesCount,
86+
@JsonProperty("failedRedeliveriesCount") long failedRedeliveriesCount,
87+
@JsonProperty("group") Optional<String> group,
88+
@JsonProperty("insertionId") Optional<String> insertionId,
89+
@JsonProperty("timestamp") Instant timestamp) {
90+
super(type, successfulRedeliveriesCount, failedRedeliveriesCount, group,insertionId, timestamp);
91+
}
92+
}
93+
94+
public static final AdditionalInformationDTOModule<EventDeadLettersRedeliveryTaskAdditionalInformationForOne, DTO> MODULE =
5095
DTOModule
5196
.forDomainObject(EventDeadLettersRedeliveryTaskAdditionalInformationForOne.class)
52-
.convertToDTO(EventDeadLettersRedeliveryTaskAdditionalInformationDTO.class)
97+
.convertToDTO(DTO.class)
5398
.toDomainObjectConverter(EventDeadLettersRedeliveryTaskAdditionalInformationDTO::fromOne)
54-
.toDTOConverter(EventDeadLettersRedeliveryTaskAdditionalInformationDTO::toDTO)
99+
.toDTOConverter((domainObject, typeName) -> new DTO(typeName,
100+
domainObject.getSuccessfulRedeliveriesCount(),
101+
domainObject.getFailedRedeliveriesCount(),
102+
domainObject.getGroup(),
103+
domainObject.getInsertionId(),
104+
domainObject.timestamp()))
55105
.typeName(EventDeadLettersRedeliverOneTask.TYPE.asString())
56106
.withFactory(AdditionalInformationDTOModule::new);
57107

@@ -66,16 +116,6 @@ public static class EventDeadLettersRedeliveryTaskAdditionalInformationForOne ex
66116
}
67117
}
68118

69-
private static EventDeadLettersRedeliveryTaskAdditionalInformationDTO toDTO(EventDeadLettersRedeliveryTaskAdditionalInformation domainObject, String typeName) {
70-
return new EventDeadLettersRedeliveryTaskAdditionalInformationDTO(
71-
typeName,
72-
domainObject.getSuccessfulRedeliveriesCount(),
73-
domainObject.getFailedRedeliveriesCount(),
74-
domainObject.getGroup(),
75-
domainObject.getInsertionId(),
76-
domainObject.timestamp());
77-
}
78-
79119
private static EventDeadLettersRedeliveryTaskAdditionalInformationForAll fromAll(EventDeadLettersRedeliveryTaskAdditionalInformationDTO dto) {
80120
return new EventDeadLettersRedeliveryTaskAdditionalInformationForAll(
81121
dto.successfulRedeliveriesCount,

0 commit comments

Comments
 (0)