Skip to content

Commit 599ec75

Browse files
📸 chore: Creature Recruitment | snapshots - dwelling data needs to be public
1 parent d9fa063 commit 599ec75

5 files changed

Lines changed: 62 additions & 9 deletions

File tree

‎generated-requests.http‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
### BuildDwelling
2-
@gameId = scenario-1
3-
@playerId = player-1
4-
@dwellingId = dwelling-1
2+
@gameId = scenario-3
3+
@playerId = player-3
4+
@dwellingId = dwelling-3
55

66
### BuildDwelling
77
PUT http://localhost:8080/games/{{gameId}}/dwellings/{{dwellingId}}

‎src/main/java/com/dddheroes/heroesofddd/GameConfiguration.java‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
package com.dddheroes.heroesofddd;
22

33
import com.dddheroes.heroesofddd.shared.application.GameMetaData;
4+
import com.dddheroes.heroesofddd.shared.infrastructure.serialization.DwellingIdSerializationModule;
5+
import com.fasterxml.jackson.databind.Module;
6+
import com.fasterxml.jackson.databind.ObjectMapper;
47
import org.axonframework.eventhandling.EventMessage;
58
import org.axonframework.eventhandling.async.SequencingPolicy;
69
import org.axonframework.messaging.correlation.CorrelationDataProvider;
710
import org.axonframework.messaging.correlation.MessageOriginProvider;
811
import org.axonframework.messaging.correlation.SimpleCorrelationDataProvider;
12+
import org.axonframework.serialization.Serializer;
13+
import org.axonframework.serialization.json.JacksonSerializer;
914
import org.springframework.context.annotation.Bean;
1015
import org.springframework.context.annotation.Configuration;
16+
import org.springframework.context.annotation.Primary;
1117

1218
@Configuration
1319
public class GameConfiguration {
@@ -26,4 +32,18 @@ public CorrelationDataProvider gameDataProvider() {
2632
public CorrelationDataProvider messageOriginProvider() {
2733
return new MessageOriginProvider();
2834
}
35+
36+
@Bean
37+
public Module dwellingIdSerializationModule() {
38+
return new DwellingIdSerializationModule();
39+
}
40+
41+
@Bean
42+
@Primary
43+
public Serializer defaultSerializer(ObjectMapper objectMapper) {
44+
objectMapper.registerModule(dwellingIdSerializationModule());
45+
return JacksonSerializer.builder()
46+
.objectMapper(objectMapper)
47+
.build();
48+
}
2949
}

‎src/main/java/com/dddheroes/heroesofddd/creaturerecruitment/write/Dwelling.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
public class Dwelling {
2727

2828
@AggregateIdentifier
29-
private DwellingId dwellingId;
30-
private CreatureId creatureId;
31-
private Resources costPerTroop;
32-
private Amount availableCreatures;
29+
public DwellingId dwellingId;
30+
public CreatureId creatureId;
31+
public Resources costPerTroop;
32+
public Amount availableCreatures;
3333

3434
@CommandHandler
3535
@CreationPolicy(AggregateCreationPolicy.CREATE_IF_MISSING) // performance downside in comparison to constructor
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.dddheroes.heroesofddd.shared.infrastructure.serialization;
2+
3+
import com.dddheroes.heroesofddd.creaturerecruitment.write.DwellingId;
4+
import com.fasterxml.jackson.core.JsonGenerator;
5+
import com.fasterxml.jackson.core.JsonParser;
6+
import com.fasterxml.jackson.databind.DeserializationContext;
7+
import com.fasterxml.jackson.databind.JsonDeserializer;
8+
import com.fasterxml.jackson.databind.JsonSerializer;
9+
import com.fasterxml.jackson.databind.SerializerProvider;
10+
import com.fasterxml.jackson.databind.module.SimpleModule;
11+
12+
import java.io.IOException;
13+
14+
public class DwellingIdSerializationModule extends SimpleModule {
15+
16+
public DwellingIdSerializationModule() {
17+
addSerializer(DwellingId.class, new DwellingIdSerializer());
18+
addDeserializer(DwellingId.class, new DwellingIdDeserializer());
19+
}
20+
21+
private static class DwellingIdSerializer extends JsonSerializer<DwellingId> {
22+
@Override
23+
public void serialize(DwellingId value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
24+
gen.writeString(value.raw());
25+
}
26+
}
27+
28+
private static class DwellingIdDeserializer extends JsonDeserializer<DwellingId> {
29+
@Override
30+
public DwellingId deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
31+
String value = p.getValueAsString();
32+
return DwellingId.of(value);
33+
}
34+
}
35+
}

‎src/main/resources/application.yaml‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ spring:
1717
hibernate:
1818
dialect: org.hibernate.dialect.PostgreSQLDialect
1919
axon:
20-
serializer:
21-
general: jackson
2220
axonserver:
2321
enabled: true
2422
eventhandling:

0 commit comments

Comments
 (0)