Skip to content
Open
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
2 changes: 1 addition & 1 deletion checkstyle-style.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
<module name="JavadocVariable">
<metadata name="net.sf.eclipsecs.core.comment" value="Checks that variables have Javadoc comments."/>
<property name="severity" value="ignore"/>
<property name="scope" value="protected"/>
<property name="accessModifiers" value="protected"/>
<metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
</module>
<module name="EqualsHashCode">
Expand Down
7 changes: 1 addition & 6 deletions elide-async/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,9 @@
<artifactId>json-path</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<groupId>tools.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import com.yahoo.elide.core.PersistentResource;
import com.yahoo.elide.core.request.Attribute;

import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ser.PropertyWriter;

import org.apache.commons.lang3.StringUtils;

import tools.jackson.core.JacksonException;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.ser.PropertyWriter;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
Expand Down Expand Up @@ -62,12 +62,12 @@ public static Map<String, Object> getProperties(ObjectMapper objectMapper,
public static Map<String, Object> getProperties(ObjectMapper objectMapper, Class<?> propertyClass) {
Map<String, Object> result = new LinkedHashMap<>();
try {
for (Iterator<PropertyWriter> iterator = objectMapper.getSerializerProviderInstance()
for (Iterator<PropertyWriter> iterator = objectMapper._serializationContext()
.findValueSerializer(propertyClass).properties(); iterator.hasNext();) {
PropertyWriter property = iterator.next();
result.put(property.getName(), getProperties(objectMapper, property.getType().getRawClass()));
}
} catch (JsonMappingException e) {
} catch (JacksonException e) {
// Do nothing
}
if (result.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.yahoo.elide.async.models.TableExport;
import com.yahoo.elide.core.request.EntityProjection;

import com.fasterxml.jackson.databind.ObjectMapper;
import tools.jackson.databind.ObjectMapper;

import java.io.OutputStream;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@
import com.yahoo.elide.core.request.EntityProjection;
import com.yahoo.elide.core.utils.coerce.CoerceUtil;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import org.apache.commons.lang3.StringUtils;

import tools.jackson.core.type.TypeReference;
import tools.jackson.databind.MapperFeature;
import tools.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.io.OutputStream;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
Expand Down Expand Up @@ -64,9 +66,12 @@ public CsvResourceWriter(OutputStream outputStream, ObjectMapper objectMapper, b
EntityProjection entityProjection) {
super(outputStream);
this.writeHeader = writeHeader;
this.objectMapper = objectMapper;
// Keep the declaration order
this.objectMapper = objectMapper.rebuild().configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, false)
.build();
this.entityProjection = entityProjection;
this.headers = entityProjection != null ? Attributes.getHeaders(objectMapper, entityProjection.getAttributes())
this.headers = entityProjection != null
? Attributes.getHeaders(this.objectMapper, entityProjection.getAttributes())
: Collections.emptyList();
}

Expand Down Expand Up @@ -138,8 +143,8 @@ protected String generateHeader(EntityProjection projection) {
return "";
}

Map<String, Attribute> attributes = projection.getAttributes().stream()
.collect(Collectors.toMap(Attribute::getName, Function.identity()));
Map<String, Attribute> attributes = projection.getAttributes().stream().collect(Collectors.toMap(
Attribute::getName, Function.identity(), (existing, replacement) -> existing, LinkedHashMap::new));
String result = headers.stream().map(header -> {
String headerValue = getHeader(header, attributes);
return quote(headerValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.yahoo.elide.async.models.TableExport;
import com.yahoo.elide.core.request.EntityProjection;

import com.fasterxml.jackson.databind.ObjectMapper;
import tools.jackson.databind.ObjectMapper;

import java.io.OutputStream;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

import com.yahoo.elide.core.PersistentResource;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import lombok.extern.slf4j.Slf4j;

import tools.jackson.core.JacksonException;
import tools.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -79,7 +79,7 @@ protected String convert(ObjectMapper mapper, PersistentResource<?> resource) {
protected String convert(ObjectMapper mapper, Map<String, Object> attributes) {
try {
return mapper.writeValueAsString(attributes);
} catch (JsonProcessingException e) {
} catch (JacksonException e) {
log.error("Exception when converting to JSON {}", e.getMessage());
throw new IllegalStateException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.yahoo.elide.async.models.TableExport;
import com.yahoo.elide.core.request.EntityProjection;

import com.fasterxml.jackson.databind.ObjectMapper;
import tools.jackson.databind.ObjectMapper;

import java.io.OutputStream;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import com.yahoo.elide.core.utils.ObjectProperties;
import com.yahoo.elide.core.utils.coerce.CoerceUtil;

import com.fasterxml.jackson.databind.ObjectMapper;

import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.CreationHelper;
Expand All @@ -25,6 +23,9 @@
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;

import tools.jackson.databind.MapperFeature;
import tools.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.io.OutputStream;
import java.time.Instant;
Expand Down Expand Up @@ -78,7 +79,9 @@ public XlsxResourceWriter(OutputStream outputStream, ObjectMapper objectMapper,
// Rows exceeding the row access window size are flushed to disk
this.workbook = new SXSSFWorkbook(rowAccessWindowSize);
this.sheet = this.workbook.createSheet();
this.headers = entityProjection != null ? Attributes.getHeaders(objectMapper, entityProjection.getAttributes())
ObjectMapper notSorted = objectMapper.rebuild().configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, false)
.build();
this.headers = entityProjection != null ? Attributes.getHeaders(notSorted, entityProjection.getAttributes())
: Collections.emptyList();
this.attributes = entityProjection != null && entityProjection.getAttributes() != null ? entityProjection
.getAttributes().stream().collect(Collectors.toMap(Attribute::getName, Function.identity()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@
import com.yahoo.elide.graphql.QueryRunner;
import com.yahoo.elide.graphql.parser.GraphQLEntityProjectionMaker;
import com.yahoo.elide.graphql.parser.GraphQLProjectionInfo;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import lombok.extern.slf4j.Slf4j;
import tools.jackson.databind.JsonNode;
import tools.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
import java.util.function.Consumer;

public class CsvExportFormatterTest {
public static final String FORMAT = "yyyy-MM-dd'T'HH:mm'Z'";
public static final String FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
private static final FastDateFormat FORMATTER = FastDateFormat.getInstance(FORMAT, TimeZone.getTimeZone("GMT"));
private HashMapDataStore dataStore;
private Elide elide;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
import com.yahoo.elide.core.RequestScope;
import com.yahoo.elide.core.request.Attribute;
import com.yahoo.elide.core.request.EntityProjection;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;

import org.junit.jupiter.api.Test;

Expand All @@ -28,6 +24,10 @@
import jakarta.persistence.Id;
import lombok.Data;

import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.cfg.DateTimeFeature;
import tools.jackson.databind.json.JsonMapper;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
Expand Down Expand Up @@ -149,7 +149,7 @@ void set() throws IOException {
""";
assertEquals(header, results.get(0));
String row = """
"name","a;b;c","VALUE1","1.0","1.0","1","1","2023-12-25T12:30:30.000000010Z","2023-12-25T12:30:30.000+00:00","2023-12-25T12:30:30.00000001","2023-12-25","2023-12-25T12:30:30.00000001Z","2023-12-25T12:30:30.00000001Z"\
"name","a;b;c","VALUE1","1.0","1.0","1","1","2023-12-25T12:30:30.000000010Z","2023-12-25T12:30:30.000Z","2023-12-25T12:30:30.00000001","2023-12-25","2023-12-25T12:30:30.00000001Z","2023-12-25T12:30:30.00000001Z"\
""";
assertEquals(row, results.get(1));
}
Expand All @@ -166,8 +166,7 @@ List<String> read(byte[] data) {

byte[] process(EntityProjection entityProjection, ResourceWriterProcessor processor) {
ObjectMapper objectMapper = JsonMapper.builder()
.addModule(new JavaTimeModule())
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.disable(DateTimeFeature.WRITE_DATES_AS_TIMESTAMPS)
.build();
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ResourceWriter writer = new CsvResourceWriter(outputStream, objectMapper, true, entityProjection)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import java.util.function.Consumer;

public class JsonExportFormatterTest {
public static final String FORMAT = "yyyy-MM-dd'T'HH:mm'Z'";
public static final String FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
private static final FastDateFormat FORMATTER = FastDateFormat.getInstance(FORMAT, TimeZone.getTimeZone("GMT"));
private HashMapDataStore dataStore;
private Elide elide;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import com.yahoo.elide.core.request.Attribute;
import com.yahoo.elide.core.request.EntityProjection;

import com.fasterxml.jackson.databind.ObjectMapper;

import org.junit.jupiter.api.Test;

import jakarta.persistence.AttributeConverter;
Expand All @@ -26,6 +24,8 @@
import jakarta.persistence.Id;
import lombok.Data;

import tools.jackson.databind.ObjectMapper;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UncheckedIOException;
Expand Down
2 changes: 1 addition & 1 deletion elide-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<artifactId>jakarta.inject-api</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<groupId>tools.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<scope>provided</scope>
</dependency>
Expand Down
14 changes: 9 additions & 5 deletions elide-core/src/main/java/com/yahoo/elide/Elide.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
import com.yahoo.elide.core.utils.coerce.CoerceUtil;
import com.yahoo.elide.core.utils.coerce.converters.ElideTypeConverter;
import com.yahoo.elide.core.utils.coerce.converters.Serde;
import com.fasterxml.jackson.databind.ObjectMapper;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import java.util.Set;
import tools.jackson.databind.ObjectMapper;

import java.util.Set;

/**
* Elide.
Expand All @@ -31,7 +31,6 @@ public class Elide {
@Getter private final ElideSettings elideSettings;
@Getter private final AuditLogger auditLogger;
@Getter private final DataStore dataStore;
@Getter private final ObjectMapper objectMapper;
@Getter private final TransactionRegistry transactionRegistry;
@Getter private final ClassScanner scanner;
private boolean initialized = false;
Expand Down Expand Up @@ -78,7 +77,6 @@ public Elide(
this.scanner = scanner;
this.auditLogger = elideSettings.getAuditLogger();
this.dataStore = new InMemoryDataStore(elideSettings.getDataStore());
this.objectMapper = elideSettings.getObjectMapper();
this.transactionRegistry = transactionRegistry;

if (doScans) {
Expand Down Expand Up @@ -136,7 +134,9 @@ protected <S, T> void registerCustomSerde(Class<T> type, Serde<S, T> serde, Stri
}

protected <S, T> void registerCustomSerdeInObjectMapper(Class<T> type, Serde<S, T> serde, String name) {
SerdeRegistrations.register(objectMapper, type, serde, name);
elideSettings.getElideMapper().customizeObjectMapper(builder -> {
SerdeRegistrations.register(builder, type, serde, name);
});
}

protected Set<Class<?>> registerCustomSerdeScan() {
Expand All @@ -146,4 +146,8 @@ protected Set<Class<?>> registerCustomSerdeScan() {
public <T extends Settings> T getSettings(Class<T> clazz) {
return this.elideSettings.getSettings(clazz);
}

public ObjectMapper getObjectMapper() {
return this.elideSettings.getElideMapper().getObjectMapper();
}
}
27 changes: 20 additions & 7 deletions elide-core/src/main/java/com/yahoo/elide/ElideMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,29 @@
*/
package com.yahoo.elide;

import com.fasterxml.jackson.databind.ObjectMapper;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.cfg.MapperBuilder;

import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.function.Consumer;

/**
* Used to store the singleton shared {@link ObjectMapper} instance.
* Used to store the shared {@link ObjectMapper} instance.
*/
@Getter
@AllArgsConstructor
public class ElideMapper {
private final ObjectMapper objectMapper;
private ObjectMapper objectMapper;

public ElideMapper(ObjectMapper objectMapper) {
this.objectMapper = objectMapper;
}

public ObjectMapper getObjectMapper() {
return objectMapper;
}

public ElideMapper customizeObjectMapper(Consumer<MapperBuilder> customizer) {
MapperBuilder builder = objectMapper.rebuild();
customizer.accept(builder);
this.objectMapper = builder.build();
return this;
}
}
Loading