-1

I have a Spring Boot Library package common-library, within it contains a DTO class, say OrderDTO [package- com.example.common.dto].

I have two microservices - Core & Notification service. In Core service I have Order class in package com.example.core.domain.

In Notification service I added common-library external dependency and created a @FeignClient class

import com.example.common.dto.OrderDTO;

@FeignClient(name = "core")
public class CoreServiceClient {
  @GetMapping("/api/v1/order/get/{id})
  OrderDTO getOrderById(@PathVariable("id") String id);
}

Now when I call the getOrderById method from Notification service, I get the below error

InvalidTypeIdException: "Could not resolve type id 'com.example.core.domain.Order' as a subtype of `com.example.common.dto.OrderDTO`: no such class found"

Now I know one simple way to resolve this issue is by creating match class Order in package com.example.core.domain.

But I want to know if there are any workarounds without needing to create same class

Ashish
  • 83
  • 7

1 Answers1

0

I figured out the issue. I was adding MappingJackson2HttpMessageConverter with ObjectMapper bean as constructor parameter

@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    converters.add(0, new MappingJackson2HttpMessageConverter(objectMapper()));
}

Which was serializing the data type information in response. Removed the objectMapper()

@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    converters.add(0, new MappingJackson2HttpMessageConverter());
}
Ashish
  • 83
  • 7