-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #983 from HubSpot/unwrap-wiresafe
Move object unwrap behavior to config object
- Loading branch information
Showing
6 changed files
with
61 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/com/hubspot/jinjava/el/JinjavaObjectUnwrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.hubspot.jinjava.el; | ||
|
||
import com.hubspot.jinjava.interpret.LazyExpression; | ||
import java.util.Optional; | ||
|
||
public class JinjavaObjectUnwrapper implements ObjectUnwrapper { | ||
|
||
@Override | ||
public Object unwrapObject(Object o) { | ||
if (o instanceof LazyExpression) { | ||
o = ((LazyExpression) o).get(); | ||
} | ||
|
||
if (o instanceof Optional) { | ||
Optional<?> optValue = (Optional<?>) o; | ||
if (!optValue.isPresent()) { | ||
return null; | ||
} | ||
|
||
o = optValue.get(); | ||
} | ||
|
||
return o; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.hubspot.jinjava.el; | ||
|
||
public interface ObjectUnwrapper { | ||
Object unwrapObject(Object o); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters