Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed OAP extension mechanizm when option is overwritten #207

Merged
merged 1 commit into from
Oct 4, 2023
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: 3 additions & 1 deletion oap-stdlib/src/main/java/oap/json/ext/ExtDeserializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ public class ExtDeserializer extends StdDeserializer<Ext> {

for( var cc : conf.ext ) {
String key = extensionKey( cc.clazz, cc.field );
var oldConf = extmap.get( key );
if ( oldConf != null && oldConf.disableOverwrite ) continue;
extmap.put( key, cc );

log.debug( "add ext rule: {} = {}", key, cc.implementation );
}
}
Expand Down Expand Up @@ -138,6 +139,7 @@ public static class ClassConfiguration {
@JsonDeserialize( using = ClassDeserializer.class )
public Class<?> clazz;
public String field;
public boolean disableOverwrite;
@JsonDeserialize( using = ClassDeserializer.class )
public Class<?> implementation;
@JsonProperty( "abstract" )
Expand Down
33 changes: 32 additions & 1 deletion oap-stdlib/src/test/java/oap/json/ext/ExtDeserializerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,19 @@
@SuppressWarnings( "unused" )
public class ExtDeserializerTest {
@Test
public void ext() {
public void extOk() {
var aaa = new Bean( TestExt.newExt( "aaa" ) );
var json = "{\"ext\":{\"value\":\"aaa\"}}";
assertThat( Binder.json.marshal( aaa ) ).isEqualTo( json );
assertThat( Binder.json.unmarshal( Bean.class, json ) )
.isEqualTo( aaa );
}

@Test
public void extOverwritten() {
var aaa = new Bean( TestExtOverwritten.newExt( "aaa" ) );
var json = "{\"ext\":{\"value\":\"aaa\"}}";
assertThat( Binder.json.marshal( aaa ) ).isEqualTo( json );
assertThat( Binder.json.unmarshal( Bean.class, json ) )
.isEqualTo( aaa );
}
Expand Down Expand Up @@ -72,6 +81,28 @@ public abstract static class Ext2 extends Ext {

}


@EqualsAndHashCode( callSuper = true )
@ToString
public static class TestExtOverwritten extends TestExt {
String valueNew;

public TestExtOverwritten() {
}

public TestExtOverwritten( String value ) {
this.valueNew = value;
}

public static TestExt newExt() {
return newExt( Bean.class, "ext", new Class[0], new Object[0] );
}

public static TestExt newExt( String value ) {
return newExt( Bean.class, "ext", new Class[] { String.class }, new Object[] { value } );
}
}

@EqualsAndHashCode( callSuper = true )
@ToString
public static class TestExt extends Ext2 {
Expand Down
8 changes: 6 additions & 2 deletions oap-stdlib/src/test/resources/META-INF/json-ext.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ ext = [
class = oap.json.ext.ExtDeserializerTest.Bean
field = ext
implementation = oap.json.ext.ExtDeserializerTest.TestExt
disableOverwrite = true
}
{
class = oap.json.ext.ExtDeserializerTest.Bean
field = ext
implementation = oap.json.ext.ExtDeserializerTest.TestExtOverwritten
}
{
class = oap.json.ext.ExtDeserializerTest.Bean
Expand All @@ -15,8 +21,6 @@ ext = [
field = ext
implementation = oap.json.ext.NpeExt
}


{
class = oap.json.TestTemplateBean
field = ext
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

<properties>

<oap.project.version>18.11.9</oap.project.version>
<oap.project.version>18.11.10</oap.project.version>

<oap.deps.testng.version>7.8.0</oap.deps.testng.version>
<oap.deps.assertj.version>3.24.2</oap.deps.assertj.version>
Expand Down
Loading