镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Looks like jackson's annotations are ignored #491

Description

@jjant

From @botbfr, aws/aws-sdk-java#2453.

Describe the issue

I have overriden RequestHandler<I, O> with my lambda. All the jackson's annotations in my pojo (PreSignUpEvent) are ignored (Tested with JsonProperty so far). => The attributes that does not require an annotation are correctly deserialized (Because the attribute's name is the same than the object attribute's name) but not the ones with 2 different names (that's why I need to use JsonProperty annotation)

I'm using jackson v2 annotations.

I tried with RequestStreamHandler, calling in my lambda 'new ObjectMapper().readValue(InputStream, MyPojo.class)' and it worked. The annotations are taken into account.

My pojo and the lambda (just for the example here, I tried with the field 'version' -> versionn):

public class PreSignUpEvent {

    @JsonProperty("version")
    private int versionn;

    private String region;


    public PreSignUpEvent() {
    }

    public int getVersionn() {
        return versionn;
    }

    public void setVersionn(int versionn) {
        this.versionn = versionn;
    }

    public String getRegion() {
        return region;
    }

    public void setRegion(String region) {
        this.region = region;
    }
@Named("validateUsername")
public class ValidateUsername implements RequestHandler<PreSignUpEvent, PreSignUpEvent> {

    @Override
    public PreSignUpEvent handleRequest(PreSignUpEvent input, Context context) {
 {
        LambdaLogger logger = context.getLogger();
        logger.log("input is "+input);
        return input;
}

logs:

{"region":"eu-west-1"} and version is ignored.

Do you have any idea ? Is it link to a reflection issue ?

Steps to Reproduce

Override RequestHandler<I, O> lambda,
Create a pojo that needs annotations to be deserialized

Activity

  1. added
    events-v4To be pulled into aws-lambda-java-event v4
    on Jul 11, 2024
  2. mancioshell commented on Jan 27, 2025

    @mancioshell

    any updated?

  3. smirnoal commented on Jan 27, 2025

    @smirnoal
    Contributor

    you might want to try custom serialisation to achieve the desired behaviour. Take a look at https://docs.aws.amazon.com/lambda/latest/dg/java-custom-serialization.html

  4. mancioshell commented on Jan 27, 2025

    @mancioshell

    you might want to try custom serialisation to achieve the desired behaviour. Take a look at https://docs.aws.amazon.com/lambda/latest/dg/java-custom-serialization.html

    Thank you for your reply.
    I'm using it for my lambda, but it seems does not work with aws-lambda-java-tests

    I have this unit test:

    @ParameterizedTest
    @Event(value = "event.json", type = UpdateTemplateEvent.class)
    public void testLambda(UpdateTemplateEvent event) throws IOException {
        OpenRewriteBuildHandler eventHandler = new OpenRewriteBuildHandler();
        eventHandler.setInjector(injector);
    
        eventHandler.handleRequest(event, context);
    }

    with this pojo:

    public class UpdateTemplateEvent {
    
        @JsonProperty("timestamp")
        public String timestamp;
    
        @JsonProperty("repo_ms")
        public String repository;
        @JsonProperty("repo_ms_commit")
        public String commit;
    
        public UpdateTemplateEvent() {
        }
    }

    but with the following json (event.json):

    {
      "timestamp": "timestamp",
      "repo_ms": "myrepot",
      "repo_ms_commit": "mycommit",
    }
    

    commit and repository field results null.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    events-v4To be pulled into aws-lambda-java-event v4

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions