Skip to content

Commit 3e9b98e

Browse files
committed
Fix codestyle
1 parent 9160740 commit 3e9b98e

File tree

5 files changed

+28
-23
lines changed

5 files changed

+28
-23
lines changed

orchestration/src/main/java/com/sap/ai/sdk/orchestration/JacksonMixins.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,4 @@ interface ModuleResultsOutputUnmaskingInnerMixIn {}
2121

2222
@JsonTypeInfo(use = JsonTypeInfo.Id.NONE)
2323
interface NoneTypeInfoMixin {}
24-
2524
}

orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationChatResponse.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@ public TokenUsage getTokenUsage() {
5555
* @return A list of all messages.
5656
*/
5757
@Nonnull
58-
public List<Message> getAllMessages() throws UnsupportedOperationException{
58+
public List<Message> getAllMessages() throws UnsupportedOperationException {
5959
final var messages = new ArrayList<Message>();
6060

61-
for (final ChatMessagesInner chatMessage : originalResponse.getModuleResults().getTemplating()) {
61+
for (final ChatMessagesInner chatMessage :
62+
originalResponse.getModuleResults().getTemplating()) {
6263
if (chatMessage instanceof ChatMessage simpleMsg) {
6364
final var message =
6465
switch (simpleMsg.getRole()) {
@@ -68,9 +69,9 @@ public List<Message> getAllMessages() throws UnsupportedOperationException{
6869
default -> throw new IllegalStateException("Unexpected role: " + simpleMsg.getRole());
6970
};
7071
messages.add(message);
71-
}
72-
else {
73-
throw new UnsupportedOperationException("Currently MultiChatMessage type not supported by convenience API");
72+
} else {
73+
throw new UnsupportedOperationException(
74+
"Currently MultiChatMessage type not supported by convenience API");
7475
}
7576
}
7677

orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class OrchestrationClient {
5252
ModuleResultsOutputUnmaskingInner.class,
5353
JacksonMixins.ModuleResultsOutputUnmaskingInnerMixIn.class);
5454

55-
var module =
55+
final var module =
5656
new SimpleModule()
5757
.addDeserializer(
5858
ChatMessagesInner.class,

orchestration/src/main/java/com/sap/ai/sdk/orchestration/PolymorphicFallbackDeserializer.java

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,36 @@
33
import com.fasterxml.jackson.annotation.JsonSubTypes;
44
import com.fasterxml.jackson.core.JsonParser;
55
import com.fasterxml.jackson.databind.DeserializationContext;
6+
import com.fasterxml.jackson.databind.JsonDeserializer;
67
import com.fasterxml.jackson.databind.JsonMappingException;
7-
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
88
import java.io.IOException;
99
import java.util.ArrayList;
1010
import java.util.List;
11+
import javax.annotation.Nonnull;
1112

1213
/**
1314
* Handles polymorphic deserialization for a base class or interface.
1415
*
15-
* <p>This deserializer attempts to deserialize JSON into a subtype of a base class or interface.
16-
* Subtypes are either discovered using the {@link JsonSubTypes} annotation or provided explicitly.
17-
* If deserialization fails for all candidates, a {@link JsonMappingException} is thrown with
18-
* suppressed exceptions.
16+
* <p>This deserializer uses a fallback strategy by attempting to deserialize the JSON into known
17+
* subtypes. Subtypes are either discovered using the {@link JsonSubTypes} annotation or provided
18+
* explicitly. If deserialization fails for all candidates, a {@link JsonMappingException} is thrown
19+
* with suppressed exceptions.
1920
*
2021
* @param <T> The base type for deserialization.
2122
*/
22-
public class PolymorphicFallbackDeserializer<T> extends StdDeserializer<T> {
23+
public class PolymorphicFallbackDeserializer<T> extends JsonDeserializer<T> {
2324

24-
private final List<Class<? extends T>> candidates;
25+
@Nonnull private final List<Class<? extends T>> candidates;
26+
Class<T> baseClass;
2527

2628
/**
2729
* Constructs the deserializer using the {@link JsonSubTypes} annotation.
2830
*
2931
* @param baseClass The base class or interface to be resolved.
3032
* @throws IllegalStateException If no subtypes are found.
3133
*/
32-
protected PolymorphicFallbackDeserializer(Class<T> baseClass) {
33-
super(baseClass);
34+
protected PolymorphicFallbackDeserializer(@Nonnull final Class<T> baseClass) {
35+
this.baseClass = baseClass;
3436

3537
final var subTypes = baseClass.getAnnotation(JsonSubTypes.class);
3638
if (subTypes == null || subTypes.value().length == 0) {
@@ -50,8 +52,8 @@ protected PolymorphicFallbackDeserializer(Class<T> baseClass) {
5052
* @param candidates A list of candidate classes to try deserialization.
5153
*/
5254
protected PolymorphicFallbackDeserializer(
53-
Class<T> baseClass, List<Class<? extends T>> candidates) {
54-
super(baseClass);
55+
@Nonnull final Class<T> baseClass, @Nonnull final List<Class<? extends T>> candidates) {
56+
this.baseClass = baseClass;
5557
this.candidates = candidates;
5658
}
5759

@@ -62,17 +64,20 @@ protected PolymorphicFallbackDeserializer(
6264
* @param deserializationContext The deserialization context.
6365
* @return The deserialized object of a matching candidate type.
6466
* @throws JsonMappingException If deserialization fails for all candidates.
65-
* @throws IOException If an I/O error occurs.
67+
* @throws IOException If json content cannot be consumed.
6668
*/
69+
@Nonnull
6770
@Override
68-
public T deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
71+
public T deserialize(
72+
@Nonnull final JsonParser jsonParser,
73+
@Nonnull final DeserializationContext deserializationContext)
6974
throws IOException {
7075

7176
final var root = jsonParser.readValueAsTree();
7277
final var throwable =
7378
JsonMappingException.from(
7479
jsonParser,
75-
"PolymorphicFallbackDeserializer failed to deserialize " + handledType().getName());
80+
"PolymorphicFallbackDeserializer failed to deserialize " + this.baseClass.getName());
7681

7782
for (final var candidate : candidates) {
7883
try {

orchestration/src/test/java/com/sap/ai/sdk/orchestration/OrchestrationUnitTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ void testGrounding() {
130130
assertThat(groundingData.get("grounding_result").toString())
131131
.startsWith("Joule is the AI copilot that truly understands your business.");
132132
assertThat(result.getModuleResults().getGrounding().getMessage()).isEqualTo("grounding result");
133-
assertThat(((ChatMessage)result.getModuleResults().getTemplating().get(0)).getContent())
133+
assertThat(((ChatMessage) result.getModuleResults().getTemplating().get(0)).getContent())
134134
.startsWith(
135135
"What does Joule do? Use the following information as additional context: Joule is the AI copilot that truly understands your business.");
136136
assertThat(llmChoice.getMessage().getContent())
@@ -578,7 +578,7 @@ void streamChatCompletionDeltas() throws IOException {
578578
assertThat(message0.get("content")).isEqualTo("");
579579
final var templating = deltaList.get(0).getModuleResults().getTemplating();
580580
assertThat(templating).hasSize(1);
581-
581+
582582
final var templateItem = (ChatMessage) templating.get(0);
583583
assertThat(templateItem.getRole()).isEqualTo("user");
584584
assertThat(templateItem.getContent())

0 commit comments

Comments
 (0)