Skip to content

Conversation

@Saramanda9988
Copy link
Contributor

What's changed?

The API response format example in the HTTP Service Discovery document does not match the actual code implementation, resulting in deserialization errors when users implement the API according to the document.

All error examples in the following 4 document files have been fixed

Incorrect format in the document:

{
  "targets": [
    "192.168.1.101:8080",
    "192.168.1.102:8080"
  ]
}

log:

2026-01-26 15:57:13 [1000000000-http_sd-target-3115] ERROR org.apache.hertzbeat.common.util.JsonUtil - Cannot deserialize value of type java.util.ArrayList<org.apache.hertzbeat.common.entity.sd.ServiceDiscoveryResponseEntity> from Object value (token JsonToken.START_OBJECT)
at [Source: REDACTED (StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION disabled); line: 1, column: 1]
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type java.util.ArrayList<org.apache.hertzbeat.common.entity.sd.ServiceDiscoveryResponseEntity> from Object value (token JsonToken.START_OBJECT)
at [Source: REDACTED (StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION disabled); line: 1, column: 1]
at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:59)
at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1767)
at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1541)
at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1488)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.handleNonArray(CollectionDeserializer.java:402)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:254)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:30)
at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.readRootValue(DefaultDeserializationContext.java:342)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4917)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3860)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3843)
at org.apache.hertzbeat.common.util.JsonUtil.fromJson(JsonUtil.java:82)
at org.apache.hertzbeat.collector.collect.sd.HttpSdCollectImpl.collect(HttpSdCollectImpl.java:87)
at org.apache.hertzbeat.collector.dispatch.MetricsCollect.run(MetricsCollect.java:202)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:840)

Code implementation in HttpSdCollectImpl.java:

String responseBody = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
TypeReference<List<ServiceDiscoveryResponseEntity>> typeReference = new TypeReference<>() {};
final List<ServiceDiscoveryResponseEntity> responseEntityList = JsonUtil.fromJson(responseBody, typeReference);
if (CollectionUtils.isEmpty(responseEntityList)) {
    return;
}

Entity definition in ServiceDiscoveryResponseEntity.java:

/**
 * Service Discovery Response Entity
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ServiceDiscoveryResponseEntity {
    private List<String> target;
}

The expected format of the actual code:

[
  {
    "target": [
      "192.168.1.101:8080",
      "192.168.1.102:8080"
    ]
  }
]

Checklist

  • I have read the Contributing Guide
  • I have written the necessary doc or comment.
  • I have added the necessary unit tests and all cases have passed.

Add or update API

  • I have added the necessary e2e tests and all cases have passed.

@github-actions github-actions bot added the doc Improvements or additions to documentation label Jan 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants