0

I have a problem and below is code:-

MainService.java

public void someMethod(Message message){

A aObj = new A (someEnumClass.enumValue, message)

someService.saveData(aObj)

}

public Class A extends B {

int x,y,z;

A(SomeEnumClass enumValue,int c){

super(enumValue);

}

Public abstract class B<EnumClass extends Enum<EnumClass>>{

private EnumClass enumValue

}

Now the above code works:

But when I test using my below class

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
public class MyDemoTests {
  @Autowired
    private SomeService someService;

    @Autowired
    private someRepo repository;


    @Test
        public void testMyservice() throws Exception {
            List<A> results = repository.findAll();
            assertThat(results).containsAll(all);

        }

I get the below error on "results":-

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `java.lang.Enum` (no Creators, like default construct, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information
 at [Source: (InputStreamReader); line: 1, column: 123] (through reference chain: com.example.A["enumValue"])

Much Appreciated. Thanks

1
  • What is opr? What is saved1? What does saved1.getI() return? How can anyone be expected to answer this question? Commented Jan 11, 2019 at 16:10

1 Answer 1

1

AFAIK, you must not extend Enum like you do! The only allowed way is public enum .... Therefore it is aly not possible to create an abstract enum base class!

Depending on what you really want to do, you might be able to achieve the same with an interface containing default methods. An enum can implements interfaces.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.