0

I have a java pojo created by jsonSchemaPojo2 as so:

@JsonInclude(JsonInclude.Include.NON_DEFAULT)
@JsonPropertyOrder({
   "CardBranding"
})

public class RewardsProcessing implements Serializable
{
    @JsonProperty("CardBranding")
    @NotNull
    private String cardBranding

    public RewardsProcessing(String cardBranding){
         this.cardBranding = cardBranding
    }

    @JsonProperty("CardBranding")
    public String getCardBranding(){return cardBranding; }
    
    @JsonProperty("CardBranding")
    public void setCardBranding(String cardBranding){ this.cardBranding = cardBranding}

}

Rewards Collection:

[
 {CardBranding : "1"},
 {CardBranding : "2"}
]

The following code parses the mongo response into the java pojo

AggregationResults results = mongoTemplate.aggregate(agg, "Rewards", RewardsProcessing.class);

The problem is that I am getting null in the resulting java object. aggregate is case sensitive.

I have two options:

  1. Make the cardBranding field upper-case by using some property in the jsonschemapojo2. I tried researching but found none. Schemapojo2 by default sets the field to lowerCase.

  2. Configure the aggregate method to ignore the case.

Thanks in Advance!!

Fernando
  • 381
  • 1
  • 5
  • 20

1 Answers1

0

Instead of using @JsonProperty which is used by jackson, use @Field annotation for the field.

@Field("CardBranding")
private String cardBranding

Need to import annotation using import org.springframework.data.mongodb.core.mapping.Field;

ashanshamika
  • 137
  • 4