Checking if two expressions are equal based on content


Is there a way to check if two expressions are equal? The below expressions are equal but they give the following output which makes a.equals(b) comparison falls (i think the id thing?)

  Expression a ="type").equalTo(Expression.string("type"));
  Expression b ="type").equalTo(Expression.string("type"));

  //BinaryExpression{@0x4ba3357,json=[=, [.type], type]}
 //BinaryExpression{@0xb368e44,json=[=, [.type], type]}

   a.equals(b); // returns false but they are equal content wise.

Currently, I am thinking of:

        convert expresions to string
        split the on the word "json"
        compare the second element of the array aArray[1].equals(bArray[1])

but is there a simple way?

For those who are curious, I do need it.

That may, incidentally, work, at the moment.

At this moment, Expression.toString includes the JSON representation of the Expression after the string “json=”. Identical Expressions (including order!) should have identical JSON representations.

This is certainly not part of our API, we do not support it, and we certainly do not guarantee that the trick will continue to work.

If you can make a case for being able to compare Expressions, please file a request for the feature.

thanks so much Blake! That shall be okay for our needs…

I am curious about your need for this - Whats the use case or the problem that you are trying to solve?

1 Like