Skip to content

Commit

Permalink
Add a test (passing in 2.9, failin 2.10) for #2576
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Dec 20, 2019
1 parent d33730c commit a4bdcef
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.fasterxml.jackson.databind.format;

import java.util.Collections;
import java.util.Map;

import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat.Shape;

Expand Down Expand Up @@ -70,6 +73,24 @@ static class ColorWrapper {
}
}

// [databind#2576]
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum Enum2576 {
DEFAULT("default"),
ATTRIBUTES("attributes") {
@Override
public String toString() {
return name();
}
};

private final String key;
private Enum2576(String key) {
this.key = key;
}
public String getKey() { return this.key; }
}

/*
/**********************************************************
/* Tests
Expand Down Expand Up @@ -113,4 +134,12 @@ public void testEnumPropertyAsNumber() throws Exception {
assertEquals(String.format(aposToQuotes("{'color':%s}"), Color.GREEN.ordinal()),
MAPPER.writeValueAsString(new ColorWrapper(Color.GREEN)));
}

// [databind#2576]
public void testEnumWithMethodOverride() throws Exception {
String stringResult = MAPPER.writeValueAsString(Enum2576.ATTRIBUTES);
Map<?,?> result = MAPPER.readValue(stringResult, Map.class);
Map<String,String> exp = Collections.singletonMap("key", "attributes");
assertEquals(exp, result);
}
}

0 comments on commit a4bdcef

Please sign in to comment.