SerializationException when send command between 2 projects

I have two projects which work with axon server, each projet configured by a context
project A → context1
project B → context2

I tried to send a command from the project A to project B

I added the below config in the project A

@Bean
    public TargetContextResolver<?> targetContextResolver() {
        return message -> message.getPayloadType().getName().startsWith("com.am") ? "context2" : "context1";
    }

application.yml project A

axon:
  serializer:
    general: jackson
    events: jackson
    messages: jackson
  deserializer:
    general: jackson
    events: jackson
    messages: jackson
  axonserver:
    clientId: context1
    keep-alive-time: 1000
    sslEnabled: true
    context: context1
    servers: node.axonserver-test.local
    token: xxxxxxxxx

application.yml project B

axon:
  serializer:
    general: jackson
    events: jackson
    messages: jackson
  deserializer:
    general: jackson
    events: jackson
    messages: jackson
  axonserver:
    clientId: context2
    keep-alive-time: 1000
    sslEnabled: true
    context: context2
    servers: node.axonserver-test.local
    token: xxxxxxxxx

but i have this error

Caused by: org.axonframework.serialization.SerializationException: Error while deserializing object
	at org.axonframework.serialization.json.JacksonSerializer.deserialize(JacksonSerializer.java:207)
	at org.axonframework.serialization.LazyDeserializingObject.getObject(LazyDeserializingObject.java:102)
	at org.axonframework.axonserver.connector.command.GrpcBackedCommandMessage.getPayload(GrpcBackedCommandMessage.java:83)
	at org.axonframework.modelling.command.AnnotationCommandTargetResolver.invokeAnnotated(AnnotationCommandTargetResolver.java:133)
	at org.axonframework.modelling.command.AnnotationCommandTargetResolver.findIdentifier(AnnotationCommandTargetResolver.java:115)
	at org.axonframework.modelling.command.AnnotationCommandTargetResolver.resolveTarget(AnnotationCommandTargetResolver.java:92)
	at org.axonframework.modelling.command.AggregateAnnotationCommandHandler$AggregateCommandHandler.handle(AggregateAnnotationCommandHandler.java:567)
	at org.axonframework.modelling.command.AggregateAnnotationCommandHandler$AggregateCommandHandler.handle(AggregateAnnotationCommandHandler.java:557)
	at org.axonframework.messaging.DefaultInterceptorChain.proceed(DefaultInterceptorChain.java:57)
	at org.axonframework.messaging.DefaultInterceptorChain.proceed(DefaultInterceptorChain.java:55)
	at org.axonframework.messaging.interceptors.LoggingInterceptor.handle(LoggingInterceptor.java:85)
	at org.axonframework.messaging.DefaultInterceptorChain.proceed(DefaultInterceptorChain.java:55)
	at org.axonframework.messaging.interceptors.CorrelationDataInterceptor.handle(CorrelationDataInterceptor.java:67)
	at org.axonframework.messaging.DefaultInterceptorChain.proceed(DefaultInterceptorChain.java:55)
	at org.axonframework.messaging.unitofwork.DefaultUnitOfWork.executeWithResult(DefaultUnitOfWork.java:77)
	at org.axonframework.commandhandling.SimpleCommandBus.lambda$handle$3(SimpleCommandBus.java:198)
	at org.axonframework.tracing.Span.run(Span.java:72)
	at org.axonframework.commandhandling.SimpleCommandBus.handle(SimpleCommandBus.java:189)
	at org.axonframework.commandhandling.SimpleCommandBus.doDispatch(SimpleCommandBus.java:163)
	at org.axonframework.commandhandling.SimpleCommandBus.dispatch(SimpleCommandBus.java:130)
	at org.axonframework.axonserver.connector.command.AxonServerCommandBus$CommandProcessingTask.run(AxonServerCommandBus.java:308)
	at org.axonframework.axonserver.connector.PriorityRunnable.run(PriorityRunnable.java:58)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('<' (code 60)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
 at [Source: (byte[])"<com.am.domain.commands.InitCommand><id>54757787</id><processId>35f1e845-b8e9-11ed-a1f9-fa163eacb093</processId><processVariables/></com.am.domain.commands.InitCommand>"; line: 1, column: 2]
	at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:2391)
	at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:735)
	at com.fasterxml.jackson.core.base.ParserMinimalBase._reportUnexpectedChar(ParserMinimalBase.java:659)
	at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._handleUnexpectedValue(UTF8StreamJsonParser.java:2737)
	at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._nextTokenNotInObject(UTF8StreamJsonParser.java:902)
	at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.nextToken(UTF8StreamJsonParser.java:794)
	at com.fasterxml.jackson.databind.ObjectReader._initForReading(ObjectReader.java:356)
	at com.fasterxml.jackson.databind.ObjectReader._bindAndClose(ObjectReader.java:2041)
	at com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:1529)
	at org.axonframework.serialization.json.JacksonSerializer.deserialize(JacksonSerializer.java:205)

Hi Aymen,

Could it be it’s reading events from before you configured the serializers? It seems it’s trying to deserialize xml, which is the default format.

commandGateway.send(MessageEvent.builder().id(id).messageName("create_new").processInstanceId(processId).build());


@AllArgsConstructor
@Getter
@Setter
public class MessageEvent {
   @TargetAggregateIdentifier
    private final String id;
    private final String messageName;
    private final String processInstanceId;
}

Hi @Gerard

i don’t understand why it deserializes to xml, i don’t send an xml format :confused:
there’s a specific format to force it to deserialize to json ?

i tried also to send a command between two projects wich are configured in the same context, some times i receive the command and some times i get this error

org.axonframework.axonserver.connector.command.AxonServerRemoteCommandHandlingException: An exception was thrown by the remote message handling component: An exception has occurred during command execution
Caused by
Caused by only whitespace content allowed before start tag and not { (position: START_DOCUMENT seen {… @1:2)

The default is xml. Do you maybe have any custom configuration, where you might not set the serializer?