Hi,

I have a simple use case where I want convert json to pojo.
All values are quoted including booleans, longs and ints.
Jsonb specification says parse$Type e.g parseInt
or
parseBoolean shall be used. These methods can take string arguments.

https://jakarta.ee/specifications/jsonb/3.0/jakarta-jsonb-spec-3.0.html#java-lang-byte-short-integer-long-float-double

I have a unit test that produces the error.


javax.json.bind.JsonbException: Missing a Converter for type int to convert the 
JSON String '20' . Please register a custom converter for it.
        at ke.mbote.jsonb.ClientTest.test(ClientTest.java:23)
Caused by: org.apache.johnzon.mapper.MapperException: Missing a Converter for 
type int to convert the JSON String '20' . Please register a custom converter 
for it.
        at ke.mbote.jsonb.ClientTest.test(ClientTest.java:23)


The test can be found athttps://github.com/chegekinuthia/jsonbissue.git


@Named
public class Client {

    @Inject
    private Jsonb jsonb;

    public Book getBook() {
        String book = "{\"id\":\"20\",\"published\":\"true\"}";
        return jsonb.fromJson(book, Book.class);

    }

}


@Classes(cdi = true, value = {Client.class, Book.class, Config.class})
@RunWith(org.apache.openejb.junit.ApplicationComposer.class)
public class ClientTest extends TestCase {

    @Inject
    private Client client;

    @Test
    public void test() throws Exception {

        Book book = client.getBook();
        assertEquals(20, book.getId());
        assertTrue(book.isPublished());

    }
}

What am I missing?

Reply via email to