Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@
<groupId>com.google.code.findbugs</groupId>
<artifactId>annotations</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.util.function.Supplier;

import com.fasterxml.jackson.annotation.JsonValue;

public class LazyExpression implements Supplier {

private final Supplier supplier;
Expand All @@ -17,6 +19,7 @@ public static LazyExpression of(Supplier supplier, String image) {
}

@Override
@JsonValue
public Object get() {
return supplier.get();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.hubspot.jinjava.interpret;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.Test;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableMap;

public class LazyExpressionTest {

@Test
public void itSerializesUnderlyingValue() throws JsonProcessingException {
LazyExpression expression = LazyExpression.of(() -> ImmutableMap.of("test", "hello", "test2", "hello2"), "{}");
assertThat(new ObjectMapper().writeValueAsString(expression)).isEqualTo("{\"test\":\"hello\",\"test2\":\"hello2\"}");
}
}