forked from Azure/azure-sdk-for-java
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Search onboard with core serializer SPI (#13496)
- Loading branch information
Showing
82 changed files
with
1,333 additions
and
743 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
4 changes: 1 addition & 3 deletions
4
sdk/core/azure-core-experimental/src/main/java/module-info.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 |
---|---|---|
@@ -1,13 +1,11 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import com.azure.core.experimental.serializer.AvroSerializerProvider; | ||
|
||
module com.azure.core.experimental { | ||
requires transitive com.azure.core; | ||
|
||
exports com.azure.core.experimental.serializer; | ||
exports com.azure.core.experimental.spatial; | ||
|
||
uses AvroSerializerProvider; | ||
uses com.azure.core.experimental.serializer.AvroSerializerProvider; | ||
} |
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
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
1 change: 1 addition & 0 deletions
1
...in/resources/META-INF/services/com.azure.core.util.serializer.MemberNameConverterProvider
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 @@ | ||
com.azure.core.serializer.json.gson.GsonJsonSerializerProvider |
88 changes: 88 additions & 0 deletions
88
...er-json-gson/src/test/java/com/azure/core/serializer/json/gson/GsonPropertyNameTests.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,88 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.core.serializer.json.gson; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.lang.reflect.Constructor; | ||
import java.lang.reflect.Field; | ||
import java.lang.reflect.Method; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
public class GsonPropertyNameTests { | ||
private static final String EXPECT_VALUE_IN_FIELD = "expectFieldName"; | ||
private static GsonJsonSerializer serializer; | ||
|
||
@BeforeAll | ||
public static void setup() { | ||
serializer = new GsonJsonSerializerProvider().createInstance(); | ||
} | ||
|
||
@Test | ||
public void testPropertyNameOnFieldName() throws NoSuchFieldException { | ||
class LocalHotel { | ||
String hotelName; | ||
} | ||
Field f = LocalHotel.class.getDeclaredField("hotelName"); | ||
|
||
assertEquals(serializer.convertMemberName(f), "hotelName"); | ||
} | ||
|
||
@Test | ||
public void testPropertyNameOnTransientIgnoredFieldName() throws NoSuchFieldException { | ||
class LocalHotel { | ||
transient String hotelName; | ||
} | ||
Field f = LocalHotel.class.getDeclaredField("hotelName"); | ||
assertNull(serializer.convertMemberName(f)); | ||
} | ||
|
||
@Test | ||
public void testPropertyNameOnFieldAnnotation() throws NoSuchFieldException { | ||
class LocalHotel { | ||
@SerializedName(value = EXPECT_VALUE_IN_FIELD) | ||
String hotelName; | ||
} | ||
Field f = LocalHotel.class.getDeclaredField("hotelName"); | ||
assertEquals(serializer.convertMemberName(f), EXPECT_VALUE_IN_FIELD); | ||
} | ||
|
||
@Test | ||
public void testPropertyNameOnFieldAnnotationWithEmptyValue() throws NoSuchFieldException { | ||
class LocalHotel { | ||
@SerializedName(value = "") | ||
String hotelName; | ||
} | ||
Field f = LocalHotel.class.getDeclaredField("hotelName"); | ||
|
||
assertEquals("", serializer.convertMemberName(f)); | ||
} | ||
|
||
@Test | ||
public void testPropertyNameOnMethodName() throws NoSuchMethodException { | ||
class LocalHotel { | ||
String hotelName; | ||
|
||
public String getHotelName() { | ||
return hotelName; | ||
} | ||
} | ||
|
||
Method m = LocalHotel.class.getDeclaredMethod("getHotelName"); | ||
|
||
assertNull(serializer.convertMemberName(m)); | ||
} | ||
|
||
@Test | ||
public void testPropertyNameOnConstructor() { | ||
Constructor<?>[] constructors = Hotel.class.getConstructors(); | ||
assertEquals(1, constructors.length); | ||
|
||
assertNull(serializer.convertMemberName(constructors[0])); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...re-core-serializer-json-gson/src/test/java/com/azure/core/serializer/json/gson/Hotel.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,15 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.core.serializer.json.gson; | ||
|
||
public class Hotel { | ||
String hotelName; | ||
|
||
public Hotel() { | ||
} | ||
|
||
public String getHotelName() { | ||
return hotelName; | ||
} | ||
} |
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
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
1 change: 1 addition & 0 deletions
1
...in/resources/META-INF/services/com.azure.core.util.serializer.MemberNameConverterProvider
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 @@ | ||
com.azure.core.serializer.json.jackson.JacksonJsonSerializerProvider |
20 changes: 20 additions & 0 deletions
20
...e-serializer-json-jackson/src/test/java/com/azure/core/serializer/json/jackson/Hotel.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,20 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.core.serializer.json.jackson; | ||
|
||
public class Hotel { | ||
transient String hotelName; | ||
|
||
public Hotel() { | ||
} | ||
|
||
public String getHotelName() { | ||
return hotelName; | ||
} | ||
|
||
public Hotel setHotelName(String hotelName) { | ||
this.hotelName = hotelName; | ||
return this; | ||
} | ||
} |
Oops, something went wrong.