samedi 29 mai 2021

What pattern I have to use to correctly call Child methodes?

I need help with how to correctly use java. Currently I rely on Jackson Object mapper and want to replace it with some pattern probably.

I have an abstract class:

@Getter
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder(toBuilder=true)
@Accessors(chain = true)
public class AbstractClass {
  private String first;
  private Object second;
}

also an extened class:

@Setter
@Getter
@EqualsAndHashCode(callSuper = true)
@SuperBuilder(toBuilder=true)
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
public class ExtendedClass extends AbstractClass {
  @Getter
  public static final String FIRST_TYPE= "EXTENDED";

  private String first;
  private Second second;

  @Getter
  public static class Second {
    private String value;
  }
}

Later I do such a lame thing probably which I need to fix, cause I don't think it's Java way to use object mapper instead of some clever pattern here:

  @SneakyThrows
  private SomeProps mapProps(String value) {
    try {
      Values values = objectMapper.readValue(value, Values.class);
      AbstractClass valueProp = values.getProp();
      var valuesType = valueProp.getFirst();
      String ExtendedClassStaticFirstValue FieldValue =
        (String) getTypeFromStatic(Extended.class);
      // TODO: want to implement more checking here 
      if (ExtendedClassStaticValue 
        .equals(valuesType)) {
        // TODO: @pdemyane: please, think about!
        Extended valueProp =
          objectMapper.readValue(objectMapper.writeValueAsString(valueProp), Extended.class);
        return map(valueProp);
      } else {
        return null;
      }
    } catch (JsonProcessingException e) {
      log.error("Json processing exception in processing source from", e);
      return null;
    }
  }

How to write code so that not to rely on Object mapper? Do I understand correctly that this is completle wrong?

Aucun commentaire:

Enregistrer un commentaire