question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature-request: Allow optional values for nested mapping if nested attribute is null

See original GitHub issue

I would like to use a nested mapping as follows:

<attribute name="something">
  <value name="${some.thing}" />
</attribute>

This normally works but crashes when the nested attribute “some” is null. I would like to be able to mark this kind of nested mapping optional (maybe giving a default value if the nesting contains a null value).

Maybe like this

<attribute name="something">
  <value name="${some.thing}" defaultValue="" />
</attribute>

A possible (working) workaround is:

<attribute name="something">
  <value name="${some}" />
</attribute>
<conversion name="nullIsEmptySting" to="something">
  return ${source} == null ? "null" : ${source}.getThing(); 
</conversion>

but that is annoying to write for all optional attributes.

Edit: Forgot to mention: Thanks for your work! I really enjoy using JMapper in my project!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
avurrocommented, Jun 20, 2016

I am going to implement the functions mentioned above, after a some study, i will decide if include this features with this release or not (giving priority to default values). The next comment will be to share the release date.

Your interest is really appreciated, thank you!

0reactions
vash95commented, Apr 13, 2020

Hi, i need a workaround, or elvis operation is now work?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handling Nulls in nested objects (Java) - Lalit Vatsal - Medium
Let's write our own NullableWrapper with mapper taking a default value at each map stage (We'll consider null otherwise). Let's call our object...
Read more >
Terraform optional nested object variable - Stack Overflow
I've read about terraform's 0.12 null default variable values, but I am not sure there is a way to specify default value for...
Read more >
Default to null on dynamic blocks - Terraform
There's any way to ignore some attributes with dynamic blocks? I have a variable file mostly looking like this: variable "buckets" { type...
Read more >
How to handle deeply-nested nullable fields in JavaScript and ...
Option 1: Enter idx. I have found idx to be a safe method of accessing these nested nullable values. A naive implementation of...
Read more >
faq - Dozer
Can I map one field into another field that is nested n layers deep in the ... How can I tell Dozer to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found