Десериализация страницы Spring Boot — PageImpl Нет конструктораJAVA

Программисты JAVA общаются здесь
Anonymous
Десериализация страницы Spring Boot — PageImpl Нет конструктора

Сообщение Anonymous »

Попытка модульного тестирования получения страницы из весенней загрузки. При использовании Javascript страницу можно легко десериализовать, но при использовании Java это не удается. Добавил конструктор по умолчанию для Spring (это принятый ответ в другом сообщении stackoverflow), но здесь он не работает.

Юнит-тест

@Test
public void test_read_pagination_happy(@Autowired ObservationSet set) {

repository.save(set);

final HttpEntity authHeaders = authentication.convert("", authSuccess);
final ParameterizedTypeReference responseType = new ParameterizedTypeReference() {
};
// final ResponseEntity result = restTemplate.exchange(base + "/api/v1/observationset", HttpMethod.GET, authHeaders, String.class);
final ResponseEntity result = restTemplate.exchange(base + "/api/v1/observationset", HttpMethod.GET, authHeaders,
responseType);
System.out.println(result.getBody());
assertSame(HttpStatus.OK, result.getStatusCode(), "incorrect status code");
}


Класс RestRespongePage

class RestResponsePage extends PageImpl {

private static final long serialVersionUID = 3248189030448292002L;

public RestResponsePage(List content, Pageable pageable, long total) {
super(content, pageable, total);
}

public RestResponsePage(List content) {
super(content);
}

public RestResponsePage() {
super(new ArrayList());
}

}


```

Код доступен на github --> https://github.com/OpenPCM /openpcm-server/blob/integration-test/src/test/java/org/openpcm/controller/ObservationSetControllerIntTest.java

При десериализации выдается следующая ошибка:

org.springframework.http.converter.HttpMessageConversionException: Type definition error: [simple type, class org.springframework.data.domain.Pageable]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `org.springframework.data.domain.Pageable` (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: (PushbackInputStream); line: 1, column: 294] (through reference chain: o r g . o p e n p c m . c o n t r o l l e r . R e s t R e s p o n s e P a g e [ " p a g e a b l e " ] ) < b r / > a t o r g . s p r i n g f r a m e w o r k . h t t p . c o n v e r t e r . j s o n . A b s t r a c t J a c k s o n 2 H t t p M e s s a g e C o n v e r t e r . r e a d J a v a T y p e ( A b s t r a c t J a c k s o n 2 H t t p M e s s a g e C o n v e r t e r . j a v a : 2 4 0 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . h t t p . c o n v e r t e r . j s o n . A b s t r a c t J a c k s o n 2 H t t p M e s s a g e C o n v e r t e r . r e a d ( A b s t r a c t J a c k s o n 2 H t t p M e s s a g e C o n v e r t e r . j a v a : 2 2 5 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . w e b . c l i e n t . H t t p M e s s a g e C o n v e r t e r E x t r a c t o r . e x t r a c t D a t a ( H t t p M e s s a g e C o n v e r t e r E x t r a c t o r . j a v a : 1 0 0 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . w e b . c l i e n t . R e s t T e m p l a t e $ R e s p o n s e E n t i t y R e s p o n s e E x t r a c t o r . e x t r a c t D a t a ( R e s t T e m p l a t e . j a v a : 9 5 9 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . w e b . c l i e n t . R e s t T e m p l a t e $ R e s p o n s e E n t i t y R e s p o n s e E x t r a c t o r . e x t r a c t D a t a ( R e s t T e m p l a t e . j a v a : 9 4 2 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . w e b . c l i e n t . R e s t T e m p l a t e . d o E x e c u t e ( R e s t T e m p l a t e . j a v a : 6 8 9 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . w e b . c l i e n t . R e s t T e m p l a t e . e x e c u t e ( R e s t T e m p l a t e . j a v a : 6 4 4 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . w e b . c l i e n t . R e s t T e m p l a t e . e x c h a n g e ( R e s t T e m p l a t e . j a v a : 5 9 3 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . b o o t . t e s t . w e b . c l i e n t . T e s t R e s t T e m p l a t e . e x c h a n g e ( T e s t R e s t T e m p l a t e . j a v a : 8 4 3 ) < b r / > a t o r g . o p e n p c m . c o n t r o l l e r . O b s e r v a t i o n S e t C o n t r o l l e r I n t T e s t . t e s t _ r e a d _ p a g i n a t i o n _ h a p p y ( O b s e r v a t i o n S e t C o n t r o l l e r I n t T e s t . j a v a : 8 5 ) < b r / > a t j a v a . b a s e / j d k . i n t e r n a l . r e f l e c t . N a t i v e M e t h o d A c c e s s o r I m p l . i n v o k e 0 ( N a t i v e M e t h o d ) < b r / > a t j a v a . b a s e / j d k . i n t e r n a l . r e f l e c t . N a t i v e M e t h o d A c c e s s o r I m p l . i n v o k e ( N a t i v e M e t h o d A c c e s s o r I m p l . j a v a : 6 2 ) < b r / > a t j a v a . b a s e / j d k . i n t e r n a l . r e f l e c t . D e l e g a t i n g M e t h o d A c c e s s o r I m p l . i n v o k e ( D e l e g a t i n g M e t h o d A c c e s s o r I m p l . j a v a : 4 3 ) < b r / > a t j a v a . b a s e / j a v a . l a n g . r e f l e c t . M e t h o d . i n v o k e ( M e t h o d . j a v a : 5 6 4 ) < b r / > a t o r g . j u n i t . p l a t f o r m . c o m m o n s . u t i l . R e f l e c t i o n U t i l s . i n v o k e M e t h o d ( R e f l e c t i o n U t i l s . j a v a : 4 3 6 ) < b r / > a t o r g . j u n i t . j u p i t e r . e n g i n e . e x e c u t i o n . E x e c u t a b l e I n v o k e r . i n v o k e ( E x e c u t a b l e I n v o k e r . j a v a : 1 1 5 ) < b r / > a t o r g . j u n i t . j u p i t e r . e n g i n e . d e s c r i p t o r . T e s t M e t h o d T e s t D e s c r i p t o r . l a m b d a $ i n v o k e T e s t M e t h o d $ 6 ( T e s t M e t h o d T e s t D e s c r i p t o r . j a v a : 1 7 0 ) < b r / > a t o r g . j u n i t . j u p i t e r . e n g i n e . e x e c u t i o n . T h r o w a b l e C o l l e c t o r . e x e c u t e ( T h r o w a b l e C o l l e c t o r . j a v a : 4 0 ) < b r / > a t o r g . j u n i t . j u p i t e r . e n g i n e . d e s c r i p t o r . T e s t M e t h o d T e s t D e s c r i p t o r . i n v o k e T e s t M e t h o d ( T e s t M e t h o d T e s t D e s c r i p t o r . j a v a : 1 6 6 ) < b r / > a t o r g . j u n i t . j u p i t e r . e n g i n e . d e s c r i p t o r . T e s t M e t h o d T e s t D e s c r i p t o r . e x e c u t e ( T e s t M e t h o d T e s t D e s c r i p t o r . j a v a : 1 1 3 ) < b r / > a t o r g . j u n i t . j u p i t e r . e n g i n e . d e s c r i p t o r . T e s t M e t h o d T e s t D e s c r i p t o r . e x e c u t e ( T e s t M e t h o d T e s t D e s c r i p t o r . j a v a : 5 8 ) < b r / > a t o r g . j u n i t . p l a t f o r m . e n g i n e . s u p p o r t . h i e r a r c h i c a l . H i e r a r c h i c a l T e s t E x e c u t o r $ N o deExecutor.lambda$executeRecursively$3(HierarchicalTestExecutor.java:112)
at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.executeRecursively(HierarchicalTestExecutor.java:108)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.execute(HierarchicalTestExecutor.java:79)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$2(HierarchicalTestExecutor.java:120)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)
at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:430)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$3(HierarchicalTestExecutor.java:120)
at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.executeRecursively(HierarchicalTestExecutor.java:108)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.execute(HierarchicalTestExecutor.java:79)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$2(HierarchicalTestExecutor.java:120)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)
at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:430)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$3(HierarchicalTestExecutor.java:120)
at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.executeRecursively(HierarchicalTestExecutor.java:108)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.execute(HierarchicalTestExecutor.java:79)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:55)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:43)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:170)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:154)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:90)
at org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.run(JUnit5TestReference.java:89)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)
Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `org.springframework.data.domain.Pageable` (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: (PushbackInputStream); line: 1, column: 294] (through reference chain: org.openpcm.controller.RestResponsePage["pageable"])
at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:67)
at com.fasterxml.jackson.databind.DeserializationContext.reportBadDefinition(DeserializationContext.java:1451)
at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1027)
at com.fasterxml.jackson.databind.deser.AbstractDeserializer.deserialize(AbstractDeserializer.java:265)
at com.fasterxml.jackson.databind.deser.impl.FieldProperty.deserializeAndSet(FieldProperty.java:136)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:288)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:151)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4013)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3084)
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:237)
... 65 more


Подробнее здесь: https://stackoverflow.com/questions/524 ... onstructor

Вернуться в «JAVA»