0

I have a method that does comparison of two jsons.

import org.json.JSONException;
import org.junit.Test;
import org.skyscreamer.jsonassert.*;
import org.skyscreamer.jsonassert.comparator.CustomComparator;

public class TestClass {

    @Test
    public void jsonCompareTest() throws JSONException {
        JSONAssert.assertEquals("{x: 1, time:123}", "{x: 1, time:234}",
                                new CustomComparator(
                                JSONCompareMode.LENIENT,
                                Customization.customization("time",
                                                            (ValueMatcher)(o1, o2) -> true)));
    }

}

So it works as expected, no issues. However, the following section is highlighted in yellow!

(ValueMatcher)(o1, o2) -> true

It gives following warning:

Unchecked assignment: 'org.skyscreamer.jsonassert.ValueMatcher' to 'org.skyscreamer.jsonassert.ValueMatcher<java.lang.Object>'
Signals places where an unchecked warning is issued by the compiler, for example:
    void f(HashMap map) {
        map.put("key", "value");
    }

If I put the following above the class, it disappears:

@SuppressWarnings("unchecked")

But is there any other way to properly fix it rather than suppress the warning?!

Please give example in the current context

Saffik
  • 911
  • 4
  • 19
  • 45
  • Do not use raw types when you use generics. – Ivan May 09 '18 at 13:30
  • @Ivan - Can you give an example in current context how to fix please? – Saffik May 09 '18 at 13:32
  • 2
    There is nothing bad to suppress that warning if you are 100% sure that it will be always class you expects. If you are not sure, you can put additional `instanceof` check for runtime to avoid ClassCastException. But in compile time you may get that warning. Still it is not a big deal to suppress that warning sometime. – Vadim May 09 '18 at 13:40
  • 1
    Try to use `ValueMatcher` or `ValueMatcher` in `(ValueMatcher)(o1, o2)` – Ivan May 09 '18 at 13:42
  • OK @Vadim - Thanks for that, I'll suppress it for now. :) – Saffik May 09 '18 at 13:42
  • Thanks @Ivan - appreciate it. – Saffik May 09 '18 at 13:42

0 Answers0