Json проблема с отображением EnhancerBySpringCGlib ['advisors'] - PullRequest
0 голосов
/ 13 апреля 2020

Я использую Spring AOP и пытаюсь использовать службу REST, которая принимает запрос json. Если я не использую Spring AOP, Джексон может проанализировать мой java запрос объекта на JSON, но когда я использую Spring AOP, я получаю следующая ошибка при использовании метода restTemplate.exchange

org.springframework.http.converter.HttpMessageConversionException: JSON mapping problem: 
    com.alight.smart.batch.model.JobRequest$$EnhancerBySpringCGLIB$$1d447c97["advisors"]-> 
    org.springframework.aop.aspectj.annotation.InstantiationModelAwarePointcutAdvisorImpl[1]->
    org.springframework.aop.aspectj.annotation.InstantiationModelAwarePointcutAdvisorImpl["declaredPointcut"]->
    org.springframework.aop.aspectj.AspectJExpressionPointcut["pointcutExpression"]->
    org.aspectj.weaver.internal.tools.PointcutExpressionImpl["underlyingPointcut"]->
    org.aspectj.weaver.patterns.AndPointcut["left"]->
    org.aspectj.weaver.patterns.KindedPointcut["signature"]->
    org.aspectj.weaver.patterns.SignaturePattern["returnType"]->
    org.aspectj.weaver.patterns.AnyTypePattern["typeParameters"]->
    org.aspectj.weaver.patterns.TypePatternList["start"];
nested exception is
com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.IllegalStateException)
(through reference chain:
    com.alight.smart.batch.model.JobRequest$$EnhancerBySpringCGLIB$$1d447c97["advisors"]->
    org.springframework.aop.aspectj.annotation.InstantiationModelAwarePointcutAdvisorImpl[1]->
    org.springframework.aop.aspectj.annotation.InstantiationModelAwarePointcutAdvisorImpl["declaredPointcut"]->
    org.springframework.aop.aspectj.AspectJExpressionPointcut["pointcutExpression"]->
    org.aspectj.weaver.internal.tools.PointcutExpressionImpl["underlyingPointcut"]->
    org.aspectj.weaver.patterns.AndPointcut["left"]->
    org.aspectj.weaver.patterns.KindedPointcut["signature"]->
    org.aspectj.weaver.patterns.SignaturePattern["returnType"]->
    org.aspectj.weaver.patterns.AnyTypePattern["typeParameters"]->
    org.aspectj.weaver.patterns.TypePatternList["start"]) 

JobRequest. java

@Component
@DisableLogging

public class JobRequest implements Serializable {

    private static final long serialVersionUID = -3009810316407639606L;
    private String input;
    private String project;
    private String type;
    private String name;
    //getters and setters
}

LoggingAdvice. java

@Aspect
@Component
public class LoggingAdvice {

    private static final Logger logger = LoggerFactory.getLogger(LoggingAdvice.class);

    @Pointcut(value="execution(* com.alight.microservice.*.*.*(..))"                              
     +"&& !@annotation(com.alight.microservice.logging.DisableLogging)"                           
     +"&& !@target(com.alight.microservice.logging.DisableLogging)") 
    public void myPointCut()
    {

    }
    @Around("myPointCut()")
    public Object applicationLogger(ProceedingJoinPoint joinPoint) throws Throwable {
        String methodName=joinPoint.getSignature().getName();
        String className=joinPoint.getTarget().getClass().toString();
        logger.info("Inside method:  "+methodName +" of class "+className);
        Object[] args = joinPoint.getArgs();
        Object obj = joinPoint.proceed();
        logger.debug("Response -->"+" "+ obj);
        logger.info("Exiting method:  "+methodName +" of class "+className);
        logger.error("No error reported in " +methodName +" of class "+className );
        return obj;
    }
}

DisableLogging. java

@Target({ElementType.CONSTRUCTOR, ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD, 
         ElementType.TYPE})
 @Retention(RetentionPolicy.RUNTIME)
 public @interface DisableLogging {

}

Подготовка контекста

public String getBatchIdFromSMART(JobRequest req) {
    String smart_url = jobContext.getSmartBulkURL();

    postAPIContext.setEndPoint(smart_url);
    postAPIContext.setMethod(HttpMethod.POST);
    postAPIContext.setResponse(null);
    postAPIContext.setResposeClassType(String.class);


    postAPIContext.setRequest(req);

    HttpHeaders headers = new HttpHeaders();
    headers.add(CommonConstants.CONTENT_TYPE, "application/xml");
    postAPIContext.setHeaders(headers);
    RestTemplate rest = new RestTemplate();

    restClient.execute(postAPIContext, req);
    return postAPIContext.getResponse();
} 

RestImpl . java

private <T> void executePost(Context<T> context) {
        int statusPost = 0;
        int retryCountPost = 0;
        HttpEntity<MultiValueMap<String, String>> request = null;
        ResponseEntity<String> exchange = null;
        String endPoint = context.getEndPoint();
    if (context.getRequestBody() != null && HttpMethod.POST.equals(context.getMethod())) {
                request = new HttpEntity<>(context.getRequestBody(), context.getHeaders());
            } else if (context.getRequestBody() == null && HttpMethod.GET.equals(context.getMethod())) {
                request = new HttpEntity<>(context.getHeaders());
            }
            do {
                retryCountPost++;
                try {

                    exchange = (ResponseEntity<String>) restTemplate.exchange(endPoint, context.getMethod(), request,
                            context.getResposeClassType());
                    statusPost = exchange.getStatusCodeValue();
                    if (exchange.getStatusCode() == HttpStatus.OK) {
                        context.setResponse((T) exchange.getBody());
                        context.setHeaders(exchange.getHeaders());
                    }
                } catch (HttpStatusCodeException e) {
                    System.out.println(retryCountPost+ " RestClientImpl.executePost(), Error Message: " + e.getResponseBodyAsString());
                } catch (Exception e) {
                    System.err.println("Exception caught while connecting to BulkSmartService" + e);
                }
            } while (retryCountPost <= 3 && statusPost != 200);
}
...