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
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
<suppress checks="Header" files=".*KeyVaultKeyResolverBCProviderTest.java"/>
<suppress checks="Header" files=".*KeyVaultKeyResolverDefaultProviderTest.java"/>
<suppress checks="Header" files="com.azure.core.http.netty.implementation.HttpProxyHandler"/>
<suppress checks="Header" files="com.azure.core.util.serializer.OptionModule"/>
<suppress checks="Header" files="com.azure.core.util.serializer.OptionPropertiesModifier"/>
<suppress checks="Header" files="com.azure.core.util.serializer.OptionBeanPropertyWriter"/>
<suppress checks="Header" files="com.azure.core.util.serializer.OptionTypeModifier"/>
<suppress checks="Header" files="com.azure.core.util.serializer.OptionSerializerProvider"/>
<suppress checks="Header" files="com.azure.core.util.serializer.OptionSerializer"/>
<suppress checks="Header" files="com.azure.core.implementation.OptionModule"/>
<suppress checks="Header" files="com.azure.core.implementation.OptionPropertiesModifier"/>
<suppress checks="Header" files="com.azure.core.implementation.OptionBeanPropertyWriter"/>
<suppress checks="Header" files="com.azure.core.implementation.OptionTypeModifier"/>
<suppress checks="Header" files="com.azure.core.implementation.OptionSerializerProvider"/>
<suppress checks="Header" files="com.azure.core.implementation.OptionSerializer"/>
<suppress checks="Header" files="eventgrid[/\\](models|implementation)[/\\].*\.java"/>

<!-- Cryptography Client exception for service client instantiation as it provides client side crypto and is not entirely based on REST service -->
Expand Down Expand Up @@ -676,7 +676,7 @@

<!-- Don't enforce non-static ClientLogger instances in com.azure.core.util.Option types-->
<suppress checks="com\.azure\.tools\.checkstyle\.checks\.(ThrowFromClientLoggerCheck|GoodLoggingCheck)"
files="com.azure.core.util.Option.java"/>
files="com.azure.core.implementation.Option.java"/>

<!-- Suppress checks in azure-core-experimental -->
<suppress checks="com.azure.tools.checkstyle.checks.ExternalDependencyExposedCheck"
Expand Down
1 change: 0 additions & 1 deletion sdk/core/azure-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

### New Features

- Added `Option<T>` to represent the states of instantiated, null, and non-null for the wrapped value.
- Added `JsonPatchDocument` to support `json-patch` functionality.
- Added new Identity `Configuration` properties.

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

package com.azure.core.util;
package com.azure.core.implementation;

import java.util.NoSuchElementException;
import java.util.Objects;

/**
* The Option type to describe tri-state. Every Option instance is in one of
* the three states: a state representing a non-null-value, null-value, or no-value.
* The Option type to describe tri-state. Every Option instance is in one of the three states: a state representing a
* non-null-value, null-value, or no-value.
*
* <p><strong>Code sample</strong></p>
* {@codesnippet com.azure.core.util.Option}
Expand Down Expand Up @@ -37,6 +37,7 @@ public static <T> Option<T> of(T value) {
* <p>
* {@code Option.empty()} is a syntactic sugar for {@code Option.of(null)}.
* </p>
*
* @param <T> The value type.
* @return an {@link Option} with a null-value.
*/
Expand All @@ -59,8 +60,8 @@ public static <T> Option<T> uninitialized() {
}

/**
* Return {@code true} if this instance is initialized with a null-value or non-null-value,
* otherwise {@code false}.
* Return {@code true} if this instance is initialized with a null-value or non-null-value, otherwise {@code
* false}.
*
* @return {@code true} if a value has been initialized, otherwise {@code false}
*/
Expand All @@ -71,8 +72,7 @@ public boolean isInitialized() {
/**
* Gets the value in the {@link Option}.
*
* @return The {@code null} (null-value) or non-null-value that the {@link Option}
* is initialized with.
* @return The {@code null} (null-value) or non-null-value that the {@link Option} is initialized with.
* @throws NoSuchElementException thrown if the {@link Option} is in no-value state.
*/
public T getValue() {
Expand All @@ -83,8 +83,7 @@ public T getValue() {
}

/**
* Indicates whether some other object is "equal to" this Option. The
* other object is considered equal if:
* Indicates whether some other object is "equal to" this Option. The other object is considered equal if:
* <ul>
* <li>it is also an {@code Option} and;
* <li>both instances are not initialized or;
Expand Down Expand Up @@ -112,13 +111,12 @@ public boolean equals(Object obj) {
}

/**
* Returns hash code of the value this Option is initialized with or -1 if in
* uninitialized state.
* Returns hash code of the value this Option is initialized with or -1 if in uninitialized state.
* <p>
* The value 0 will be returned when initialized with {@code null}.
* </p>
* @return hash code of the value this Option is initialized with or -1 if in
* uninitialized state.
*
* @return hash code of the value this Option is initialized with or -1 if in uninitialized state.
*/
@Override
public int hashCode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
* Portions Copyright (c) Microsoft Corporation
*/

package com.azure.core.util.serializer;
package com.azure.core.implementation;

import com.azure.core.util.Option;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.io.SerializedString;
import com.fasterxml.jackson.databind.PropertyName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
* Portions Copyright (c) Microsoft Corporation
*/

package com.azure.core.util.serializer;
package com.azure.core.implementation;

import com.azure.core.util.Option;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.Module;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
* Portions Copyright (c) Microsoft Corporation
*/

package com.azure.core.util.serializer;
package com.azure.core.implementation;

import com.azure.core.util.Option;
import com.fasterxml.jackson.databind.BeanDescription;
import com.fasterxml.jackson.databind.SerializationConfig;
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
* Portions Copyright (c) Microsoft Corporation
*/

package com.azure.core.util.serializer;
package com.azure.core.implementation;

import com.azure.core.util.Option;
import com.fasterxml.jackson.databind.BeanProperty;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
Expand All @@ -35,37 +34,37 @@ final class OptionSerializer extends ReferenceTypeSerializer<Option<?>> {
private static final long serialVersionUID = 1L;

OptionSerializer(ReferenceType fullType,
boolean staticTyping,
TypeSerializer typeSerializer,
JsonSerializer<Object> valueSerializer) {
boolean staticTyping,
TypeSerializer typeSerializer,
JsonSerializer<Object> valueSerializer) {
super(fullType, staticTyping, typeSerializer, valueSerializer);
}

private OptionSerializer(OptionSerializer base,
BeanProperty property,
TypeSerializer typeSerializer,
JsonSerializer<?> valueSerializer,
NameTransformer transformer,
Object suppressableValue,
boolean suppressNulls) {
BeanProperty property,
TypeSerializer typeSerializer,
JsonSerializer<?> valueSerializer,
NameTransformer transformer,
Object suppressableValue,
boolean suppressNulls) {
super(base, property, typeSerializer,
valueSerializer, transformer,
suppressableValue, suppressNulls);
}

@Override
protected ReferenceTypeSerializer<Option<?>> withResolved(BeanProperty property,
TypeSerializer typeSerializer,
JsonSerializer<?> valueSerializer,
NameTransformer transformer) {
TypeSerializer typeSerializer,
JsonSerializer<?> valueSerializer,
NameTransformer transformer) {
return new OptionSerializer(this, property, typeSerializer,
valueSerializer, transformer,
super._suppressableValue, super._suppressNulls);
}

@Override
public ReferenceTypeSerializer<Option<?>> withContentInclusion(Object suppressableValue,
boolean suppressNulls) {
boolean suppressNulls) {
return new OptionSerializer(this, super._property, super._valueTypeSerializer,
super._valueSerializer, super._unwrapper,
suppressableValue, suppressNulls);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
* Portions Copyright (c) Microsoft Corporation
*/

package com.azure.core.util.serializer;
package com.azure.core.implementation;

import com.azure.core.util.Option;
import com.fasterxml.jackson.databind.BeanDescription;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.MapperFeature;
Expand All @@ -37,10 +36,10 @@ final class OptionSerializerProvider extends Serializers.Base implements java.io

@Override
public JsonSerializer<?> findReferenceSerializer(SerializationConfig config,
ReferenceType refType,
BeanDescription beanDesc,
TypeSerializer contentTypeSerializer,
JsonSerializer<Object> contentValueSerializer) {
ReferenceType refType,
BeanDescription beanDesc,
TypeSerializer contentTypeSerializer,
JsonSerializer<Object> contentValueSerializer) {
if (Option.class.isAssignableFrom(refType.getRawClass())) {
// The standard Serializers.Base implementations for reference types honor
// USE_STATIC_TYPING flag (e.g. Optional in Jdk8Module), do the same for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
* Portions Copyright (c) Microsoft Corporation
*/

package com.azure.core.util.serializer;
package com.azure.core.implementation;

import com.azure.core.util.Option;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.type.ReferenceType;
import com.fasterxml.jackson.databind.type.TypeBindings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@

package com.azure.core.models;

import com.azure.core.util.Option;
import com.azure.core.implementation.Option;
import com.azure.core.util.logging.ClientLogger;
import com.azure.core.util.serializer.JacksonAdapter;
import com.azure.core.util.serializer.JsonSerializer;
import com.azure.core.util.serializer.JsonSerializerProviders;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonValue;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand All @@ -23,9 +25,13 @@ public final class JsonPatchDocument {
private static final Object SERIALIZER_INSTANTIATION_SYNCHRONIZER = new Object();
private static volatile JsonSerializer defaultSerializer;

@JsonIgnore
private final ClientLogger logger = new ClientLogger(JsonPatchDocument.class);

@JsonIgnore
private final JsonSerializer serializer;

@JsonValue
private final List<JsonPatchOperation> operations;

/**
Expand Down Expand Up @@ -54,7 +60,7 @@ public JsonPatchDocument(JsonSerializer serializer) {
*
* @return The JSON patch operations in this JSON patch document.
*/
public List<JsonPatchOperation> getOperations() {
List<JsonPatchOperation> getOperations() {
return new ArrayList<>(operations);
}

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

package com.azure.core.util.serializer;
package com.azure.core.models;

import com.azure.core.util.CoreUtils;
import com.azure.core.models.JsonPatchDocument;
import com.azure.core.models.JsonPatchOperation;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
package com.azure.core.models;

import com.azure.core.annotation.Immutable;
import com.azure.core.util.Option;
import com.azure.core.implementation.Option;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import java.util.Objects;
import java.util.Optional;
Expand All @@ -13,7 +14,8 @@
* Represents a JSON Patch operation.
*/
@Immutable
public final class JsonPatchOperation {
@JsonSerialize(using = JsonPatchOperationSerializer.class)
final class JsonPatchOperation {
private final JsonPatchOperationKind op;
private final String from;
private final String path;
Expand Down Expand Up @@ -42,7 +44,7 @@ public final class JsonPatchOperation {
*
* @return The kind of operation.
*/
public JsonPatchOperationKind getOp() {
JsonPatchOperationKind getOp() {
return op;
}

Expand All @@ -51,7 +53,7 @@ public JsonPatchOperationKind getOp() {
*
* @return The operation from target path.
*/
public String getFrom() {
String getFrom() {
return from;
}

Expand All @@ -60,7 +62,7 @@ public String getFrom() {
*
* @return The operation target path.
*/
public String getPath() {
String getPath() {
return path;
}

Expand All @@ -71,7 +73,7 @@ public String getPath() {
*
* @return The operation value.
*/
public Option<String> getValue() {
Option<String> getValue() {
return value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* Represents the JSON Patch operation kind.
*/
public enum JsonPatchOperationKind {
enum JsonPatchOperationKind {
/**
* Add operation.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.core.util.serializer;
package com.azure.core.models;

import com.azure.core.models.JsonPatchOperation;
import com.azure.core.util.Option;
import com.azure.core.implementation.Option;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,16 +288,13 @@ private static <T extends ObjectMapper> T initializeObjectMapper(T mapper) {
.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true)
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
.registerModule(new JavaTimeModule())
.registerModule(new OptionModule())
.registerModule(ByteArraySerializer.getModule())
.registerModule(Base64UrlSerializer.getModule())
.registerModule(DateTimeSerializer.getModule())
.registerModule(DateTimeDeserializer.getModule())
.registerModule(DateTimeRfc1123Serializer.getModule())
.registerModule(DurationSerializer.getModule())
.registerModule(HttpHeadersSerializer.getModule())
.registerModule(JsonPatchDocumentSerializer.getModule())
.registerModule(JsonPatchOperationSerializer.getModule())
.registerModule(UnixTimeSerializer.getModule());
mapper.setVisibility(mapper.getSerializationConfig().getDefaultVisibilityChecker()
.withFieldVisibility(JsonAutoDetect.Visibility.ANY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

package com.azure.core.util;

import com.azure.core.implementation.Option;

import java.util.NoSuchElementException;

/**
Expand Down
Loading