seems that jackson have some problems when parse super number
Gson failed at once, but jackson block long times and then failed
because jackson parse the super number to BigInteger first and then convert 
to target number type.

i write a reproduce test case
please help me to resolve the problem, thanks

package test.jackson;

import java.util.concurrent.Callable;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Strings;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class DoS {
  static String input = Strings.repeat("1", 100_0000);

  static Gson gson = new GsonBuilder().create();

  static ObjectMapper mapper = new ObjectMapper();

  public static enum Color {
    WHITE,
    BLACK
  }

  static void run(String name, Callable callable) {
    System.out.println(name);

    long start = System.currentTimeMillis();
    try {
      Object result = callable.call();
      System.out.println("  result:" + result);
    } catch (Throwable e) {
      //System.out.println("  failed: " + e.getMessage());
      System.out.println("  failed");
    }
    System.out.println("  time:" + (System.currentTimeMillis() - start) + " 
ms");
  }

  public static void main(String[] args) {
    run("Gson enum:", () -> gson.fromJson(input, Color.class));
    run("Jackson enum:", () -> mapper.readValue(input, Color.class));
    System.out.println();

    // byte/Byte/short/Short/int/Integer/long/Long
    // all these types, jackson is very slow
    run("Gson int:", () -> gson.fromJson(input, int.class));
    run("Jackson int:", () -> mapper.readValue(input, int.class));
    System.out.println();

    // float/Float/double/Double
    // all these types, jackson is very slow
    run("Gson double:", () -> gson.fromJson(input, double.class));
    run("Jackson double:", () -> mapper.readValue(input, double.class));
    System.out.println();
  }
}


the output is :
Gson enum:
  result:null
  time:16 ms
Jackson enum:
  failed
  time:17469 ms

Gson int:
  failed
  time:32 ms
Jackson int:
  failed
  time:17392 ms

Gson double:
  result:Infinity
  time:8 ms
Jackson double:
  result:Infinity
  time:18187 ms



-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to