| package com.fasterxml.jackson.databind.introspect; |
| |
| import com.fasterxml.jackson.annotation.*; |
| |
| import com.fasterxml.jackson.core.*; |
| import com.fasterxml.jackson.databind.*; |
| import com.fasterxml.jackson.databind.introspect.VisibilityChecker; |
| |
| public class TestAutoDetect |
| extends BaseMapTest |
| { |
| static class PrivateBean { |
| String a; |
| |
| private PrivateBean() { } |
| |
| private PrivateBean(String a) { this.a = a; } |
| } |
| |
| /* |
| /******************************************************** |
| /* Unit tests |
| /******************************************************** |
| */ |
| |
| public void testPrivateCtor() throws Exception |
| { |
| // first, default settings, with which construction works ok |
| ObjectMapper m = new ObjectMapper(); |
| PrivateBean bean = m.readValue("\"abc\"", PrivateBean.class); |
| assertEquals("abc", bean.a); |
| |
| // then by increasing visibility requirement: |
| m = new ObjectMapper(); |
| VisibilityChecker<?> vc = m.getVisibilityChecker(); |
| vc = vc.withCreatorVisibility(JsonAutoDetect.Visibility.PUBLIC_ONLY); |
| m.setVisibility(vc); |
| try { |
| m.readValue("\"abc\"", PrivateBean.class); |
| fail("Expected exception for missing constructor"); |
| } catch (JsonProcessingException e) { |
| verifyException(e, "no String-argument constructor/factory"); |
| } |
| } |
| |
| } |