java2typescript icon indicating copy to clipboard operation
java2typescript copied to clipboard

NullPointerException fix

Open schurik opened this issue 9 years ago • 6 comments

in com.fasterxml.jackson.databind.ext.CoreXMLSerializers the visitor is passed with a null as JavaType. Because of this a NPE could be thrown in TSJsonFormatVisotorWrapper.expectStringFormat(null)

schurik avatar Nov 16 '16 14:11 schurik

@schurik, both Your commits contain lots of formatting changes that every other developer might want to reformat according to their preferences. Could undo the formatting changes?

I'm also wondering in which situation that NPE reveals itslef. There are lots of tests for jackson module, probably I've missed smth.

atsu85 avatar Nov 18 '16 19:11 atsu85

@atsu85 I will undo the formatting changes. I am using XMLGregorianCalender in my model. Inside the CoreXMLSerialie.acceptJsonFormatVisitor method the visitor and null is passed to the delegate. And in case TSJsonFormatVisitorWrapper.expectStringFormat() the type is null. Here the NPE occurs

schurik avatar Nov 18 '16 20:11 schurik

@schurik, thanks for undoing the formatting changes.

I tried to quickly reproduce the issue this PR should address, but i probably tried smth different, as everything seemed to work well, when I added

public XMLGregorianCalendar _XMLGregorianCalendar;

to DefinitionGeneratorTest.TestClass, the output included the field with number type that seems to be expected:


export interface TestClass {
    _XMLGregorianCalendar: number;
   // other fields and methods
}

What did You do differently? Perhaps You could even create/update the test for this issue Yourself?

atsu85 avatar Nov 21 '16 15:11 atsu85

In my case my model needs to be serialized as JSON and/or XML. My property has an addition @JsonFormat anntotation.

This is my setup: @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.sss'Z'", timezone = "GMT") public XMLGregorianCalendar _someDate;

and the output is: export interface TestClass { _XMLGregorianCalendar: string; }

and while serializing _someDate I get NPE without the null check

schurik avatar Nov 21 '16 16:11 schurik

@schurik, thanks, I'll add the test myself. Could You also squash the commits into single commit?

atsu85 avatar Nov 21 '16 16:11 atsu85

Hi @schurik, I had pretty-much forgotten this after failing to reproduce the NPE You reported and tried to fix with this PR. Please see my comments from the commit that tries to create the test for reproducing the NPE.

Please help me to figure out how to reproduce this issue, so the test could be updated and i could merge the fix.

atsu85 avatar Feb 18 '17 17:02 atsu85