{"action":"created","issue":{"url":"https://api.github.com/repos/FasterXML/jackson-databind/issues/731","labels_url":"https://api.github.com/repos/FasterXML/jackson-databind/issues/731/labels{/name}","comments_url":"https://api.github.com/repos/FasterXML/jackson-databind/issues/731/comments","events_url":"https://api.github.com/repos/FasterXML/jackson-databind/issues/731/events","html_url":"https://github.com/FasterXML/jackson-databind/issues/731","id":63864545,"number":731,"title":"XmlAdapter result marshaling error in case of ValueType=Object ","user":{"login":"Spikhalskiy","id":532108,"avatar_url":"https://avatars.githubusercontent.com/u/532108?v=3","gravatar_id":"","url":"https://api.github.com/users/Spikhalskiy","html_url":"https://github.com/Spikhalskiy","followers_url":"https://api.github.com/users/Spikhalskiy/followers","following_url":"https://api.github.com/users/Spikhalskiy/following{/other_user}","gists_url":"https://api.github.com/users/Spikhalskiy/gists{/gist_id}","starred_url":"https://api.github.com/users/Spikhalskiy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Spikhalskiy/subscriptions","organizations_url":"https://api.github.com/users/Spikhalskiy/orgs","repos_url":"https://api.github.com/users/Spikhalskiy/repos","events_url":"https://api.github.com/users/Spikhalskiy/events{/privacy}","received_events_url":"https://api.github.com/users/Spikhalskiy/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-03-24T00:27:39Z","updated_at":"2015-04-02T20:39:43Z","closed_at":null,"body":"Hi,\r\n\r\nI have an error \"com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class java.lang.String and no properties discovered to create BeanSerializer\" in case of using custom XmlAdapter with such declaration:\r\n```java\r\npublic static class IntegerListXmlAdapter extends XmlAdapter<Object, List<Integer>> {\r\n        ...\r\n        @Override\r\n        public Object marshal(List<Integer> list) throws Exception {\r\n            return Joiner.on(\",\").join(list);\r\n        }\r\n}\r\n```\r\nIf change declaration of this class to \"extends XmlAdapter<String, List<Integer>>\" it works good.\r\n\r\nFull example:\r\n\r\n```java\r\npublic class IntegerListXmlAdapterTest {\r\n    @Test\r\n    public void testBasic() throws JsonProcessingException {\r\n        ObjectMapper mapper = (new ObjectMapper()).setAnnotationIntrospector(new JaxbAnnotationIntrospector());\r\n        SomeIntListHolder listHolder = new SomeIntListHolder();\r\n        listHolder.setListOne(asList(1, 2, 3));\r\n        System.out.println(mapper.writeValueAsString(listHolder));\r\n    }\r\n\r\n    public static class IntegerListXmlAdapter extends XmlAdapter<Object, List<Integer>> {\r\n        @Override\r\n        public List<Integer> unmarshal(Object value) throws Exception {return null;}\r\n\r\n        @Override\r\n        public Object marshal(List<Integer> list) throws Exception {\r\n            return Joiner.on(\",\").join(list);\r\n        }\r\n    }\r\n\r\n    public static class IntegerListToStringXmlAdapter extends XmlAdapter<String, List<Integer>> {\r\n        public List<Integer> unmarshal(String value) throws Exception {return null;}\r\n\r\n        public String marshal(List<Integer> list) throws Exception {\r\n            return Joiner.on(\",\").join(list);\r\n        }\r\n    }\r\n\r\n    @XmlRootElement\r\n    @XmlAccessorType(XmlAccessType.NONE)\r\n    public static class SomeIntListHolder {\r\n\r\n        @XmlAttribute\r\n        @XmlJavaTypeAdapter(IntegerListXmlAdapter.class)\r\n        private List<Integer> listOne;\r\n\r\n        public List<Integer> getListOne() {\r\n            return listOne;\r\n        }\r\n\r\n        public void setListOne(List<Integer> listOne) {\r\n            this.listOne = listOne;\r\n        }\r\n    }\r\n}\r\n```\r\nIn this state with last Jackson version we will get an error\r\n```\r\ncom.fasterxml.jackson.databind.JsonMappingException: No serializer found for class java.lang.String and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: SomeIntListHolder[\"listOne\"])\r\n\tat com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.failForEmpty(UnknownSerializer.java:59)\r\n\tat com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.serialize(UnknownSerializer.java:26)\r\n\tat com.fasterxml.jackson.databind.ser.std.StdDelegatingSerializer.serialize(StdDelegatingSerializer.java:157)\r\n\tat com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:575)\r\n\tat com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:663)\r\n\tat com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:156)\r\n\tat com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:129)\r\n\tat com.fasterxml.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:3385)\r\n\tat com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(ObjectMapper.java:2779)\r\n```\r\nBut if we change XmlJavaTypeAdapter to IntegerListToStringXmlAdapter error will be fixed and code will work fine.\r\nThis error exists only in Jackson 2, we have this code with Object generic on Jackson 1 and get an issue only during migration to new major version.\r\n\r\nThis concrete error can be fixed by hack in com.fasterxml.jackson.databind.ser.std.StdDelegatingSerializer:\r\n```java\r\n    @Override\r\n    public void serialize(Object value, JsonGenerator gen, SerializerProvider provider) throws IOException\r\n    {\r\n        Object delegateValue = convertValue(value);\r\n        // should we accept nulls?\r\n        if (delegateValue == null) {\r\n            provider.defaultSerializeNull(gen);\r\n            return;\r\n        }\r\n\r\n        //original code:\r\n        //_delegateSerializer.serialize(delegateValue, gen, provider);\r\n\r\n        JsonSerializer<Object> delegateSerializer;\r\n        if (_delegateSerializer instanceof UnknownSerializer) {\r\n            delegateSerializer =  provider.findValueSerializer(delegateValue.getClass());\r\n        } else {\r\n            delegateSerializer = _delegateSerializer;\r\n        }\r\n\r\n        delegateSerializer.serialize(delegateValue, gen, provider);\r\n    }\r\n```\r\n\r\nYou can find test class here: https://github.com/Spikhalskiy/jackson_xmladapter__bug/blob/master/src/test/java/IntegerListXmlAdapterTest.java\r\n\r\nand hacked serializer code here: https://github.com/Spikhalskiy/jackson_xmladapter__bug/blob/master/src/main/java/com/fasterxml/jackson/databind/ser/std/StdDelegatingSerializer.java\r\n\r\nNow test passing in this repo because of fake StdDelegatingSerializer in classpath - try to delete it to get an issue."},"comment":{"url":"https://api.github.com/repos/FasterXML/jackson-databind/issues/comments/89039659","html_url":"https://github.com/FasterXML/jackson-databind/issues/731#issuecomment-89039659","issue_url":"https://api.github.com/repos/FasterXML/jackson-databind/issues/731","id":89039659,"user":{"login":"cowtowncoder","id":55065,"avatar_url":"https://avatars.githubusercontent.com/u/55065?v=3","gravatar_id":"","url":"https://api.github.com/users/cowtowncoder","html_url":"https://github.com/cowtowncoder","followers_url":"https://api.github.com/users/cowtowncoder/followers","following_url":"https://api.github.com/users/cowtowncoder/following{/other_user}","gists_url":"https://api.github.com/users/cowtowncoder/gists{/gist_id}","starred_url":"https://api.github.com/users/cowtowncoder/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cowtowncoder/subscriptions","organizations_url":"https://api.github.com/users/cowtowncoder/orgs","repos_url":"https://api.github.com/users/cowtowncoder/repos","events_url":"https://api.github.com/users/cowtowncoder/events{/privacy}","received_events_url":"https://api.github.com/users/cowtowncoder/received_events","type":"User","site_admin":false},"created_at":"2015-04-02T20:39:43Z","updated_at":"2015-04-02T20:39:43Z","body":"Ah. Only now fully understood the issue -- right, dynamic meaning that since type is not specified as anything more than `java.lang.Object`, converter can not access it yet.\r\nI was able to use the provided test which is great, and I think I can use the pull request (big thanks for providing that!) as the starting point. I may choose slightly different route for tackling, but the basic idea is sound and I like it.\r\n"}}