Don't want to TypeReference package being obfuscated

Hey! Hope you are well! I’m trying to obfuscate an application but I’m having problems with the TypeReference packet

I’m using the package “com.fasterxml.jackson.core.type.TypeReference;” to read a json file, I use the following code to read it:

mapper.readValue(new File(JSONFile), new TypeReference<Map<String, UserTO>>() { }

breaking down the code to find the error, I found that the error is in the following code:

TypeReference typeReference = new TypeReference<Map<String, UserTO>>() { };

After obfuscation I get a new class:

import com.fasterxml.jackson.core.type.TypeReference;

final class d extends TypeReference {
d() {
}
}

So I’m losing the property <Map<String, UserTO>> of TypeReference because my method is modified to:

d var2 = new d();

I searched if there is some way not to obfuscate a method, but I didn’t find it, is it possible not to obfuscate the body of a method?

Besides, I also provide a keep to the package

 keep 'class com.fasterxml.jackson.core.type.TypeReference {*; } '

or
keep ‘class com.fasterxml.jackson.core. **’

but it had no effect.

Is there a way to keep the Map types or the only solution is to create a class that does the method and not obfuscate it? I think I don’t need to lose this type <Map<String, UserTO>> when the program creates the new TypeReference.

PD: On my ProguardTask I have the properties dontshrink() and dontoptimize().

Thank you so much!

Hi @Leicht ,

Thanks for raising this question.

Could you please try to use the following keep rule?:

-keep class * extends TypeReference {*;}

If tis keep rule would not solve the issue, could you share the content of the JSONFile with us? Kind regards,

Ewout

Hi @ewoutd ,

It doesn’t work properly…

Finally, I got it fixed using this keep.

keepattributes('Signature')

Thank you!

Leicht, Marc.

2 Likes

Hi @Leicht ,

Thank you for letting us know that you were able to solve the issue!

Kind regards,

Ewout

1 Like