Skip to content

Commit

Permalink
Add regression test
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCockx committed Jun 24, 2024
1 parent 1bccf79 commit ad58313
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.fasterxml.jackson.dataformat.xml;

import com.fasterxml.jackson.core.json.PackageVersion;
import com.fasterxml.jackson.databind.AnnotationIntrospector;
import com.fasterxml.jackson.databind.module.SimpleModule;

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

import javax.xml.stream.*;

import com.fasterxml.jackson.core.json.PackageVersion;
import org.codehaus.stax2.XMLInputFactory2;
import org.codehaus.stax2.io.Stax2ByteArraySource;
import org.codehaus.stax2.io.Stax2CharArraySource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import javax.xml.stream.XMLStreamWriter;

import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.json.PackageVersion;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.cfg.CoercionAction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
import com.fasterxml.jackson.core.exc.StreamConstraintsException;
import com.fasterxml.jackson.core.io.IOContext;
import com.fasterxml.jackson.core.io.NumberInput;
import com.fasterxml.jackson.core.json.PackageVersion;
import com.fasterxml.jackson.core.util.ByteArrayBuilder;
import com.fasterxml.jackson.core.util.JacksonFeatureSet;

import com.fasterxml.jackson.dataformat.xml.PackageVersion;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.dataformat.xml.XmlNameProcessor;
import com.fasterxml.jackson.dataformat.xml.util.CaseInsensitiveNameSet;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.fasterxml.jackson.dataformat.xml;

import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.AnnotationIntrospector;
import com.fasterxml.jackson.databind.PropertyName;
import com.fasterxml.jackson.databind.introspect.Annotated;
import com.fasterxml.jackson.databind.module.SimpleModule;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Arrays;
import java.util.List;

/**
* A regression test for https://github.com/FasterXML/jackson-databind/issues/4595
*/
public class CustomAnnotationIntrospectorNoWrapperTest extends XmlTestBase {
private final XmlMapper MAPPER = newMapper();

public void testNoWrapper() throws Exception {
Foo foo = new Foo(Arrays.asList("Value1", "Value2"));

assertEquals("<Foo><bar><bar>Value1</bar><bar>Value2</bar></bar></Foo>", MAPPER.writeValueAsString(foo));

MAPPER
.registerModule(new SimpleModule("NoWrapperModule") {
@Override
public void setupModule(SetupContext context) {
context.insertAnnotationIntrospector(new NoWrapperIntrospector());
super.setupModule(context);
}
});

// TODO: update after fixing https://github.com/FasterXML/jackson-databind/issues/4595
// Should be assertEquals("<Foo><bar>Value1</bar><bar>Value2</bar></Foo>", MAPPER.writeValueAsString(foo));
assertEquals("<Foo><bar><bar>Value1</bar><bar>Value2</bar></bar></Foo>", MAPPER.writeValueAsString(foo));
}

public static class Foo {
private final List<String> bar;

public Foo(List<String> bar) {
this.bar = bar;
}

@NoWrapper
public List<String> getBar() {
return bar;
}
}

public static class NoWrapperIntrospector extends AnnotationIntrospector {
@Override
public Version version() {
return com.fasterxml.jackson.databind.cfg.PackageVersion.VERSION;
}

@Override
public PropertyName findWrapperName(Annotated ann) {
if (ann.hasAnnotation(NoWrapper.class)) {
return PropertyName.NO_NAME;
}
return super.findWrapperName(ann);
}
}

@Retention(RetentionPolicy.RUNTIME)
public @interface NoWrapper {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.core.Versioned;
import com.fasterxml.jackson.core.json.PackageVersion;

public class VersionInfoTest extends XmlTestBase
{
Expand Down

0 comments on commit ad58313

Please sign in to comment.