@@ -446,30 +446,26 @@ private static void appendVarDef(StringBuilder lines, Binding parameter) {
446446 append (lines , String .format ("%s _%s_ = %s;" , typeName , parameter .name , DEFAULT_VALUES .get (typeName )));
447447 }
448448
449- public static String genObjectUsingSkip (Class clazz , ConstructorDescriptor ctor ) {
450- StringBuilder lines = new StringBuilder ();
451- append (lines , "if (iter.readNull()) { return null; }" );
452- append (lines , "{{clazz}} set = {{newInst}};" );
453- append (lines , "iter.skip();" );
454- append (lines , "return set;" );
455- return lines .toString ()
456- .replace ("{{clazz}}" , clazz .getCanonicalName ())
457- .replace ("{{newInst}}" , genNewInstCode (clazz , ctor ));
458- }
459-
460449 private static String genNewInstCode (Class clazz , ConstructorDescriptor ctor ) {
461450 StringBuilder code = new StringBuilder ();
462451 if (ctor .parameters .isEmpty ()) {
463452 // nothing to bind, safe to reuse existing set
464453 code .append ("(com.jsoniter.CodegenAccess.existingObject(iter) == null ? " );
465454 }
466- if (ctor .staticMethodName == null ) {
467- code .append (String .format ("new %s" , clazz .getCanonicalName ()));
455+ if (ctor .objectFactory != null ) {
456+ code .append (String .format ("(%s)com.jsoniter.spi.JsoniterSpi.create(%s.class)" ,
457+ clazz .getCanonicalName (), clazz .getCanonicalName ()));
468458 } else {
469- code .append (String .format ("%s.%s" , clazz .getCanonicalName (), ctor .staticMethodName ));
459+ if (ctor .staticMethodName == null ) {
460+ code .append (String .format ("new %s" , clazz .getCanonicalName ()));
461+ } else {
462+ code .append (String .format ("%s.%s" , clazz .getCanonicalName (), ctor .staticMethodName ));
463+ }
470464 }
471465 List <Binding > params = ctor .parameters ;
472- appendInvocation (code , params );
466+ if (ctor .objectFactory == null ) {
467+ appendInvocation (code , params );
468+ }
473469 if (ctor .parameters .isEmpty ()) {
474470 // nothing to bind, safe to reuse existing set
475471 code .append (String .format (" : (%s)com.jsoniter.CodegenAccess.resetExistingObject(iter))" , clazz .getCanonicalName ()));
0 commit comments