1515import org .eclipse .debug .core .ILaunchConfiguration ;
1616import org .eclipse .debug .core .ILaunchConfigurationWorkingCopy ;
1717
18- import com .google .gson .Gson ;
18+ import com .fasterxml .jackson .core .JsonProcessingException ;
19+ import com .fasterxml .jackson .databind .DeserializationFeature ;
20+ import com .fasterxml .jackson .databind .ObjectMapper ;
1921import com .microsoft .azure .toolkit .lib .common .exception .AzureToolkitRuntimeException ;
2022
2123public class LaunchConfigurationUtils {
22- private static final Gson gson = new Gson ();
24+ private static final ObjectMapper mapper = new ObjectMapper ();
25+ static {
26+ mapper .configure (DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES , false );
27+ }
2328
2429 public static <T > T getFromConfiguration (ILaunchConfiguration config , @ Nonnull Class <T > classOfT ) {
2530 try {
@@ -35,15 +40,15 @@ public static <T> T getFromConfiguration(ILaunchConfiguration config, @Nonnull C
3540 value = config .getAttribute (field .getName (), 0 );
3641 } else {
3742 final String json = config .getAttribute (field .getName (), StringUtils .EMPTY );
38- value = StringUtils .isEmpty (json ) ? null : gson . fromJson (json , field .getType ());
43+ value = StringUtils .isEmpty (json ) ? null : mapper . readValue (json , field .getType ());
3944 }
4045 if (value != null ) {
4146 FieldUtils .writeField (field , obj , value , true );
4247 }
4348 }
4449 return obj ;
4550 } catch (NoSuchMethodException | SecurityException | InvocationTargetException | InstantiationException
46- | IllegalAccessException | CoreException ex ) {
51+ | IllegalAccessException | CoreException | JsonProcessingException ex ) {
4752 throw new AzureToolkitRuntimeException ("Cannot use reflections on class:" + classOfT .getSimpleName (), ex );
4853 }
4954 }
@@ -57,12 +62,11 @@ public static <T> void saveToConfiguration(@Nonnull T obj, ILaunchConfigurationW
5762 } else if (value instanceof String || value instanceof Boolean || value instanceof Integer ) {
5863 config .setAttribute (field .getName (), value );
5964 } else {
60- config .setAttribute (field .getName (), gson . toJson (value ));
65+ config .setAttribute (field .getName (), mapper . writeValueAsString (value ));
6166 }
6267 }
63- } catch (SecurityException | IllegalAccessException ex ) {
64- throw new AzureToolkitRuntimeException ("Cannot use reflections on class:" + obj .getClass ().getSimpleName (),
65- ex );
68+ } catch (SecurityException | IllegalAccessException | JsonProcessingException ex ) {
69+ throw new AzureToolkitRuntimeException ("Cannot use reflections on class:" + obj .getClass ().getSimpleName (), ex );
6670 }
6771 }
6872}
0 commit comments