Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request - support custom jackson object mapper #29

Closed
liorhar opened this issue Aug 10, 2021 · 3 comments
Closed

Feature Request - support custom jackson object mapper #29

liorhar opened this issue Aug 10, 2021 · 3 comments

Comments

@liorhar
Copy link

liorhar commented Aug 10, 2021

It would be useful if the object mapper used to serialize the template parameters was customizable.
For example, the built-in object mapper uses PropertyNamingStrategy.UPPER_CAMEL_CASE while we prefer LOWER_CAMEL_CASE
Also, we're using Kotlin so registering the kotlin module would be very useful

@ibalosh
Copy link
Contributor

ibalosh commented Aug 19, 2021

Hi @liorhar

could you share bit more details on where do you use this and in which scenario? Are you referring to template model, when sending emails with templates?

Thanks

@liorhar liorhar changed the title Feature Request - support customer jackson object mapper Feature Request - support custom jackson object mapper Aug 20, 2021
@ibalosh ibalosh closed this as completed Sep 20, 2021
@valh1996
Copy link

valh1996 commented May 30, 2023

Hi @ibalosh
I'm trying to send a List of DTO through setTemplateModel():

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class PeriodData {
    public LocalDate start;
    public LocalDate end;
}
List<PeriodData> periods = this.periodService.getPeriods(contract);
HashMap<String, Object> model = new HashMap<>() {{
    put("periods", periods);
   //
}};

TemplatedMessage message = new TemplatedMessage(senderAddress, recipient);
message.setMessageStream("outbound");
message.setTemplateId(templateId);
message.setTemplateModel(model);
postmarkClient.deliverMessageWithTemplate(message);

However, I encounter the following error:

Java 8 date/time type `java.time.LocalDate` not supported by default

The ObjectMapper defined here does not seem to have the Java Time module configured. Is there a fix please?

Update:
As a workaround, I use my own ObjectMapper to transform my model to json before sending it into the request:

message.setTemplateModel(mapper.writeValueAsString(model));

@ibalosh
Copy link
Contributor

ibalosh commented Jun 7, 2023

Hi @valh1996

Sorry for the late response. At the moment, we suggest transforming the model for specific objects, just the way you did in the workaround. If you would like to file a feature request that we could add in future, please create a separate feature request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants