Skip to content

Commit 46bc622

Browse files
committed
bugfix: fix default value initialization and deprecated API usage
- Remove @NoArgsConstructor and add explicit no-arg constructor to properly initialize @Builder.Default values - Fix connectionPoolKeepAliveDuration default value check from 1 to 10 - Replace deprecated PropertyNamingStrategy with PropertyNamingStrategies
1 parent 6c673d8 commit 46bc622

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

core/src/main/java/ai/z/openapi/core/config/ZaiConfig.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import lombok.AllArgsConstructor;
44
import lombok.Builder;
5-
import lombok.NoArgsConstructor;
65
import lombok.Setter;
76

87
import java.util.Map;
@@ -17,7 +16,6 @@
1716
*/
1817
@Setter
1918
@Builder
20-
@NoArgsConstructor
2119
@AllArgsConstructor
2220
public class ZaiConfig {
2321

@@ -128,12 +126,30 @@ public class ZaiConfig {
128126
@Builder.Default
129127
private String source_channel = "java-sdk";
130128

129+
/**
130+
* No-arg constructor that mirrors all {@link Builder.Default} field values. Lombok's
131+
* {@code @NoArgsConstructor} does not apply {@code @Builder.Default} values, so we
132+
* write this constructor explicitly to ensure every field starts with the same
133+
* defaults as the builder.
134+
*/
135+
public ZaiConfig() {
136+
this.expireMillis = 30 * 60 * 1000;
137+
this.alg = "HS256";
138+
this.disableTokenCache = true;
139+
this.connectionPoolMaxIdleConnections = 5;
140+
this.connectionPoolKeepAliveDuration = 10;
141+
this.connectionPoolTimeUnit = TimeUnit.SECONDS;
142+
this.timeOutTimeUnit = TimeUnit.SECONDS;
143+
this.source_channel = "java-sdk";
144+
}
145+
131146
/**
132147
* Constructor with combined API secret key.
133148
* @param apiKey combined secret key in format {apiKey}.{apiSecret}
134149
* @throws RuntimeException if apiSecretKey format is invalid
135150
*/
136151
public ZaiConfig(String apiKey) {
152+
this();
137153
this.apiKey = apiKey;
138154
String[] arrStr = apiKey.split("\\.");
139155
if (arrStr.length != 2) {
@@ -251,7 +267,7 @@ public int getConnectionPoolMaxIdleConnections() {
251267
* variable fallback.
252268
*/
253269
public long getConnectionPoolKeepAliveDuration() {
254-
if (connectionPoolKeepAliveDuration != 1) { // If not default value
270+
if (connectionPoolKeepAliveDuration != 10) { // If not default value
255271
return connectionPoolKeepAliveDuration;
256272
}
257273
String propValue = System.getProperty(ENV_CONNECTION_POOL_KEEP_ALIVE);

core/src/main/java/ai/z/openapi/service/deserialize/MessageDeserializeFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.fasterxml.jackson.annotation.JsonInclude;
44
import com.fasterxml.jackson.databind.DeserializationFeature;
55
import com.fasterxml.jackson.databind.ObjectMapper;
6-
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
6+
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
77
import com.fasterxml.jackson.databind.module.SimpleModule;
88
import ai.z.openapi.service.assistant.AssistantChoice;
99
import ai.z.openapi.service.deserialize.assistant.AssistantChoiceDeserializer;
@@ -14,7 +14,7 @@ public static ObjectMapper defaultObjectMapper() {
1414
ObjectMapper mapper = new ObjectMapper();
1515
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
1616
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
17-
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
17+
mapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
1818
SimpleModule module = new SimpleModule();
1919

2020
module.addDeserializer(AssistantChoice.class, new AssistantChoiceDeserializer());

0 commit comments

Comments
 (0)