@@ -34,6 +34,10 @@ public final class SerializableErrorTest {
3434            .build ();
3535    private  static  final  ObjectMapper  mapper  = ObjectMappers .newServerObjectMapper ();
3636
37+     private  static  SerializableError  deserialize (String  serialized ) throws  IOException  {
38+         return  mapper .readValue (serialized , SerializableError .class );
39+     }
40+ 
3741    @ Test 
3842    public  void  forException_should_keep_both_safe_and_unsafe_args () {
3943        ErrorType  error  = ErrorType .FAILED_PRECONDITION ;
@@ -109,15 +113,59 @@ public void testDeserializationFailsWhenNeitherErrorNameNorMessageIsSet() throws
109113    }
110114
111115    @ Test 
112-     public  void  asConjure_converts_json_nicely () throws  IOException  {
116+     public  void  asConjure_converts_remoting3_json () throws  IOException  {
113117        assertThat (deserialize ("{\" errorCode\" :\" code\" ,\" errorName\" :\" name\" }" ).asConjure ())
114118                .isEqualTo (com .palantir .conjure .java .api .errors .SerializableError .builder ()
115119                        .errorCode ("code" )
116120                        .errorName ("name" )
117121                        .build ());
118122    }
119123
120-     private  static  SerializableError  deserialize (String  serialized ) throws  IOException  {
121-         return  mapper .readValue (serialized , SerializableError .class );
124+     @ Test 
125+     public  void  asConjure_converts_remoting2_json () throws  IOException  {
126+         assertThat (deserialize ("{\" exceptionClass\" :\" java.lang.IllegalStateException\" ," 
127+                 + "\" message\" :\" Human readable message\" }" ).asConjure ())
128+                 .isEqualTo (com .palantir .conjure .java .api .errors .SerializableError .builder ()
129+                         .exceptionClass ("java.lang.IllegalStateException" )
130+                         .message ("Human readable message" )
131+                         .build ());
132+     }
133+ 
134+     @ Test 
135+     public  void  asConjure_converts_json_with_both_remoting2_and_remoting3_fields () throws  IOException  {
136+         assertThat (deserialize ("{\" errorCode\" :\" PERMISSION_DENIED\" ,\" errorName\" :\" Product:SomethingBroke\" ," 
137+                 + "\" exceptionClass\" :\" java.lang.IllegalStateException\" ,\" message\" :\" Human readable message\" ," 
138+                 + "\" errorInstanceId\" :\" 7d345390-e41d-49dd-8dcb-38dd716c0347\" ,\" parameters\" :{\" a\" :\" 1\" }}" )
139+                 .asConjure ())
140+                 .isEqualTo (com .palantir .conjure .java .api .errors .SerializableError .builder ()
141+                         .errorCode ("PERMISSION_DENIED" )
142+                         .errorName ("Product:SomethingBroke" )
143+                         .errorInstanceId ("7d345390-e41d-49dd-8dcb-38dd716c0347" )
144+                         .putParameters ("a" , "1" )
145+                         .build ());
146+     }
147+ 
148+     @ Test 
149+     public  void  all_fields_are_preserved_when_present () throws  IOException  {
150+         String  string  = "{\n " 
151+                 + "    \" errorCode\" :\" CONFLICT\" ,\n " 
152+                 + "    \" errorName\" :\" Product:TransactionConflict\" ,\n " 
153+                 + "    \" errorInstanceId\" :\" 7d345390-e41d-49dd-8dcb-38dd716c0347\" ,\n " 
154+                 + "    \" parameters\" :{},\n " 
155+                 + "    \" exceptionClass\" :\" CONFLICT\" ,\n " 
156+                 + "    \" message\" :\" Refer to the server logs with this errorInstanceId: " 
157+                 + "7d345390-e41d-49dd-8dcb-38dd716c0347\" \n " 
158+                 + "}" ;
159+ 
160+         com .palantir .conjure .java .api .errors .SerializableError  expected  =
161+                 com .palantir .conjure .java .api .errors .SerializableError .builder ()
162+                 .errorCode ("CONFLICT" )
163+                 .errorName ("Product:TransactionConflict" )
164+                 .errorInstanceId ("7d345390-e41d-49dd-8dcb-38dd716c0347" )
165+                 .message ("Refer to the server logs with this errorInstanceId: 7d345390-e41d-49dd-8dcb-38dd716c0347" )
166+                 .exceptionClass ("CONFLICT" )
167+                 .build ();
168+ 
169+         assertThat (deserialize (string ).asConjure ()).isEqualTo (expected );
122170    }
123171}
0 commit comments