Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 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 eng/versioning/version_client.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ com.azure:azure-messaging-eventhubs;5.1.2;5.2.0-beta.1
com.azure:azure-messaging-eventhubs-checkpointstore-blob;1.1.2;1.2.0-beta.1
com.azure:azure-messaging-servicebus;7.0.0-beta.3;7.0.0-beta.4
com.azure:azure-search-documents;11.0.0;11.1.0-beta.1
com.azure:azure-search-documents-serializer-json-jackson;1.0.0;1.0.0-beta.1
com.azure:azure-security-keyvault-certificates;4.0.4;4.1.0-beta.4
com.azure:azure-security-keyvault-keys;4.1.4;4.2.0-beta.5
com.azure:azure-security-keyvault-secrets;4.1.4;4.2.0-beta.4
Expand Down Expand Up @@ -71,6 +72,9 @@ com.microsoft.azure:spring-data-cosmosdb;3.0.0-beta.1;3.0.0-beta.1
# note: The unreleased dependencies will not be manipulated with the automatic PR creation code.

unreleased_com.azure:azure-messaging-servicebus;7.0.0-beta.4
unreleased_com.azure:azure-core-experimental;1.0.0-beta.2
unreleased_com.azure:azure-core-serializer-json-jackson;1.0.0-beta.2
unreleased_com.azure-search-documents-serializer-json-jackson;1.0.0-beta.1

# Released Beta dependencies: Copy the entry from above, prepend "beta_", remove the current
# version and set the version to the released beta. Released beta dependencies are only valid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/**
* Deserializes a JSON object into a {@link Geometry}.
*/
final class GeometryDeserializer extends JsonDeserializer<Geometry> {
public final class GeometryDeserializer extends JsonDeserializer<Geometry> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine for testing this, in the future when this work is merged into Azure Core it'll become package private again.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I think it doesn't hurt to public the serializer before we move back Azure Core.

private static final ClientLogger LOGGER = new ClientLogger(GeometryDeserializer.class);

/*
Expand Down Expand Up @@ -60,6 +60,10 @@ final class GeometryDeserializer extends JsonDeserializer<Geometry> {
.addDeserializer(CollectionGeometry.class, geometrySubclassDeserializer(CollectionGeometry.class));
}

public static SimpleModule getModule() {
return MODULE;
}

@Override
public Geometry deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
return read(ctxt.readTree(p));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@
/**
* Serializes a {@link Geometry} into JSON.
*/
final class GeometrySerializer extends JsonSerializer<Geometry> {
public final class GeometrySerializer extends JsonSerializer<Geometry> {
private static final ClientLogger LOGGER = new ClientLogger(GeometrySerializer.class);

static final SimpleModule MODULE;

static {
MODULE = new SimpleModule();
MODULE.addSerializer(Geometry.class, new GeometrySerializer());
/**
* Gets a module wrapping this serializer as an adapter for the Jackson
* ObjectMapper.
*
* @return a simple module to be plugged onto Jackson ObjectMapper.
*/
public static SimpleModule getModule() {
SimpleModule module = new SimpleModule();
module.addSerializer(Geometry.class, new GeometrySerializer());
return module;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
exports com.azure.core.experimental.serializer;
exports com.azure.core.experimental.spatial;

opens com.azure.core.experimental.spatial to com.fasterxml.jackson.databind;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't believe this needs to open to databind as no databinding will happen with the types in spatial. They all should be using streaming deserialization.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It indeed complaint about the PointGeometry did not open module to databind. Why spatial doesn't need to do reflection when serialize?

uses com.azure.core.experimental.serializer.AvroSerializerProvider;
uses com.azure.core.experimental.serializer.JsonSerializerProvider;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class GeometrySerializerTests {
private static final ObjectMapper MAPPER;

static {
MAPPER = new ObjectMapper().registerModule(GeometrySerializer.MODULE);
MAPPER = new ObjectMapper().registerModule(GeometrySerializer.getModule());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
import com.fasterxml.jackson.databind.ObjectMapper;

/**
* Fluent builder class that configures and instantiates instances of {@link JacksonJsonSerializer}.
* Fluent builder class that configures and instantiates instances of {@link JacksonSearchSerializer}.
*/
public final class JacksonJsonSerializerBuilder {
private ObjectMapper objectMapper;

/**
* Constructs a new instance of {@link JacksonJsonSerializer} with the configurations set in this builder.
* Constructs a new instance of {@link JacksonSearchSerializer} with the configurations set in this builder.
*
* @return A new instance of {@link JacksonJsonSerializer}.
* @return A new instance of {@link JacksonSearchSerializer}.
*/
public JacksonJsonSerializer build() {
public JacksonSearchSerializer build() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was the Azure Core implementation renamed? Just prototyping?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Caused by IDE refactoring

return (objectMapper == null)
? new JacksonJsonSerializer(new ObjectMapper())
: new JacksonJsonSerializer(objectMapper);
? new JacksonSearchSerializer(new ObjectMapper())
: new JacksonSearchSerializer(objectMapper);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* Implementation of {@link JsonSerializerProvider}.
*/
public class JacksonJsonSerializerProvider implements JsonSerializerProvider {
public class JacksonSearchJsonSerializerProvider implements JsonSerializerProvider {
@Override
public JsonSerializer createInstance() {
return new JacksonJsonSerializerBuilder().build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
/**
* Jackson based implementation of the {@link JsonSerializer} interface.
*/
public final class JacksonJsonSerializer implements JsonSerializer {
public final class JacksonSearchSerializer implements JsonSerializer {
private final ObjectMapper mapper;

/**
* Constructs a {@link JsonSerializer} using the passed Jackson serializer.
*
* @param mapper Configured Jackson serializer.
*/
JacksonJsonSerializer(ObjectMapper mapper) {
JacksonSearchSerializer(ObjectMapper mapper) {
this.mapper = mapper;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import com.azure.core.serializer.json.jackson.JacksonSearchJsonSerializerProvider;

module com.azure.core.serializer.json.jackson {
requires transitive com.azure.core;
requires transitive com.azure.core.experimental;

exports com.azure.core.serializer.json.jackson;

provides com.azure.core.experimental.serializer.JsonSerializerProvider
with com.azure.core.serializer.json.jackson.JacksonJsonSerializerProvider;
with JacksonSearchJsonSerializerProvider;
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
com.azure.core.serializer.json.jackson.JacksonJsonSerializerProvider
com.azure.core.serializer.json.jackson.JacksonSearchJsonSerializerProvider
126 changes: 126 additions & 0 deletions sdk/search/azure-search-documents-serializer-jackson/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<!--
~ Copyright (c) Microsoft Corporation. All rights reserved.
~ Licensed under the MIT License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.azure</groupId>
<artifactId>azure-client-sdk-parent</artifactId>
<version>1.7.0</version> <!-- {x-version-update;com.azure:azure-client-sdk-parent;current} -->
<relativePath>../../parents/azure-client-sdk-parent</relativePath>
</parent>

<groupId>com.azure</groupId>
<artifactId>azure-search-documents-serializer-jackson</artifactId>
<packaging>jar</packaging>
<version>1.0.0-beta.1</version> <!-- {x-version-update;com.azure:azure-search-documents-serializer-json-jackson;current} -->

<name>Microsoft Azure Search Jackson JSON Serializer Library</name>
<description>This package contains the Jackson JSON serializer client plugin for azure-search-documents.</description>
<url>https://github.com/Azure/azure-sdk-for-java</url>

<licenses>
<license>
<name>The MIT License (MIT)</name>
<url>http://opensource.org/licenses/MIT</url>
<distribution>repo</distribution>
</license>
</licenses>

<distributionManagement>
<site>
<id>azure-java-build-docs</id>
<url>${site.url}/site/${project.artifactId}</url>
</site>
</distributionManagement>

<scm>
<url>https://github.com/Azure/azure-sdk-for-java</url>
<connection>scm:git:https://github.com/Azure/azure-sdk-for-java.git</connection>
<developerConnection>scm:git:https://github.com/Azure/azure-sdk-for-java.git</developerConnection>
</scm>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<legal><![CDATA[[INFO] Any downloads listed may be third party software. Microsoft grants you no rights for third party software.]]></legal>
</properties>

<developers>
<developer>
<id>microsoft</id>
<name>Microsoft</name>
</developer>
</developers>

<dependencies>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-experimental</artifactId>
<version>1.0.0-beta.2</version> <!-- {x-version-update;com.azure:azure-core;dependency} -->
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-search-documents-serializer</artifactId>
<version>1.0.0-beta.1</version>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.6.2</version> <!-- {x-version-update;org.junit.jupiter:junit-jupiter-api;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.6.2</version> <!-- {x-version-update;org.junit.jupiter:junit-jupiter-engine;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.6.2</version> <!-- {x-version-update;org.junit.jupiter:junit-jupiter-params;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.0.0</version><!-- {x-version-update;org.mockito:mockito-core;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<version>3.3.5.RELEASE</version> <!-- {x-version-update;io.projectreactor:reactor-test;external_dependency} -->
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
<profile>
<id>java-lts</id>
<activation>
<jdk>[11,)</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version> <!-- {x-version-update;org.apache.maven.plugins:maven-surefire-plugin;external_dependency} -->
<configuration>
<argLine>
--add-exports com.azure.search.documents.serializer.json.jackson/com.azure.search.documents.serializer.json.jackson=com.fasterxml.jackson.databind
--add-opens com.azure.search.documents.serializer.json.jackson/com.azure.search.documents.serializer.json.jackson=ALL-UNNAMED
</argLine>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.search.documents.serializer.jackson;

import com.azure.core.util.logging.ClientLogger;
import com.azure.search.documents.serializer.SearchSerializer;
import com.azure.search.documents.serializer.SearchType;
import com.azure.search.documents.serializer.SerializationInclusion;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.TypeFactory;

import java.io.IOException;
import java.io.Reader;

public class SearchJacksonSerializer implements SearchSerializer {
private final ClientLogger logger = new ClientLogger(SearchJacksonSerializer.class);
private final ObjectMapper mapper;
private final TypeFactory typeFactory;

SearchJacksonSerializer(ObjectMapper mapper) {
this.mapper = mapper;
this.typeFactory = mapper.getTypeFactory();
}

@Override
public <T> T convertValue(Object o, SearchType<T> type) {
return mapper.convertValue(o, typeFactory.constructType(type.getType()));
}

@Override
public <T> T convertValue(Object o, SearchType<T> type, SerializationInclusion inclusion) {
if (inclusion == SerializationInclusion.ALWAYS) {
mapper.setSerializationInclusion(JsonInclude.Include.ALWAYS);
}
return mapper.convertValue(o, typeFactory.constructType(type.getType()));
}

@Override
public <T> T convertValue(Object o, Class<T> clazz) {
return mapper.convertValue(o, clazz);
}

@Override
public <T> T convertValue(Object o, Class<T> clazz, SerializationInclusion inclusion) {
if (inclusion == SerializationInclusion.ALWAYS) {
mapper.setSerializationInclusion(JsonInclude.Include.ALWAYS);
}
return mapper.convertValue(o, clazz);
}

@Override
public <T> T readValue(Reader reader, SearchType<T> type) {
try {
return mapper.readValue(reader, typeFactory.constructType(type.getType()));
} catch (IOException ex) {
throw logger.logExceptionAsError(new RuntimeException(ex));
}
}

@Override
public <T> T readValue(String jsonString, SearchType<T> type) {
try {
return mapper.readValue(jsonString, typeFactory.constructType(type.getType()));
} catch (IOException ex) {
throw logger.logExceptionAsError(new RuntimeException(ex));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.search.documents.serializer.jackson;

import com.azure.core.util.serializer.JacksonAdapter;
import com.azure.search.documents.serializer.SearchSerializer;
import com.azure.search.documents.serializer.jackson.implementation.SerializationUtil;
import com.fasterxml.jackson.databind.ObjectMapper;

public class SearchJacksonSerializerBuilder {
private ObjectMapper objectMapper;
private static final ObjectMapper DEFAULT_MAPPER;
static {
DEFAULT_MAPPER = new JacksonAdapter().serializer();
SerializationUtil.configureMapper(DEFAULT_MAPPER);
}

/**
* Constructs a new instance of {@link SearchSerializer} with the configurations set in this builder.
*
* @return A new instance of {@link SearchSerializer}.
*/
public SearchSerializer build() {
return (objectMapper == null)
? new SearchJacksonSerializer(DEFAULT_MAPPER)
: new SearchJacksonSerializer(objectMapper);
}

/**
* Sets the {@link ObjectMapper} that will be used during serialization.
* <p>
* If this is set to {@code null} the default {@link ObjectMapper} will be used.
*
* @param objectMapper {@link ObjectMapper} that will be used during serialization.
* @return The updated JacksonJsonSerializerBuilder class.
*/
public SearchJacksonSerializerBuilder serializer(ObjectMapper objectMapper) {
this.objectMapper = objectMapper;
return this;
}
}
Loading