I am getting the following error from my REST interface:
Problem deserializing property 'calculationStartDate' (expected type:
[simple type, class java.time.LocalDate]; actual type:
org.joda.time.LocalDate)
This is very strange, because I am not using Joda time at all. I am using Java 8 with the Java 8 DateTime API.
Here's a snap of the entity class code in question:
#ApiModelProperty(
value = "De datum waarvoor de berekening moet worden uitgevoerd.",
required = true)
#JsonDeserialize(using = LocalDateDeserializer.class)
#JsonSerialize(using = LocalDateSerializer.class)
private LocalDate calculationStartDate;
And here are all the imports for this class:
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.joda.deser.LocalDateDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import java.time.LocalDate;
import javax.xml.bind.annotation.XmlRootElement;
So why do I get this error in the response body???
I am using WildFly 10, with the original FasterXML (2.5.4) replaced for FasterXML 2.6.3 and coding in plain Java EE 7 with swagger and jackson-datatype-jsr310 added in my pom.xml:
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jaxrs</artifactId>
<version>1.5.9</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.6.3</version>
</dependency>
Very stupid. I imported the wrong deserializer:
import com.fasterxml.jackson.datatype.joda.deser.LocalDateDeserializer;
should of course be:
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
Problem solved!
Related
My problem is related to picocontainer,i am not able to figure out what I am doing wrong when executing the test runner I am unable to find any scenarios or steps.However when I execute my old file the tests runs correctly which doesnot have picocontainer reference.
My project contains following file
1) 1 Step definition
2) Feature File
2) Runner File
4) Test Context (Sharing state file,here I have mentioned webdriver and page object elements)
POM FIle
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.5</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>4.8.0</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>4.8.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-jvm-deps -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-jvm-deps</artifactId>
<version>1.0.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>4.8.0</version>
</dependency>
Feature File
Feature: Automated End2End Tests
Description: The Purpose of this feature is to test End 2 End integration.
Scenario:Customer place an order by purchasing an item from search
Given user is on Home page
When he search for "dress"
And choose to buy the item for first time
And moves to checkout from mini cart
And enter personal details on checkout page and place the order
Step Definition
package stepDefinitions;
import cucumber.TestContext;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.When;
import pageObjects.HomePage;
public class HomePageSteps {
TestContext testContext;
HomePage homePage;
public HomePageSteps(TestContext context) {
this.testContext = context;
homePage = testContext.getPageObjectManager().getHomePage();
}
#Given("^user is on Home Page$")
public void user_is_on_Home_Page(){
homePage.navigateTo_HomePage();
}
#When("^he search for \"([^\"]*)\"$")
public void he_search_for(String product) {
homePage.perform_Search(product);
}
}
Runner File
package runners;
import org.junit.runner.RunWith;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
//import cucumber.api.java.ObjectFactory;T
#RunWith(Cucumber.class)
#CucumberOptions(
// junit = "--step-notifications",
features = "src/test/resources/functionalTests",
glue= {"stepDefinitions"})
public class TestRunner {
}
Test Context
package cucumber;
import managers.PageObjectManager;
import managers.WebDriverManager;
public class TestContext {
private WebDriverManager webDriverManager;
private PageObjectManager pageObjectManager;
public TestContext(){
webDriverManager = new WebDriverManager();
pageObjectManager = new PageObjectManager(webDriverManager.getDriver());
}
public WebDriverManager getWebDriverManager() {
return webDriverManager;
}
public PageObjectManager getPageObjectManager() {
return pageObjectManager;
}
}
I encounter a strange problem.
I created an database using embedded neo4j whose path is "/Users/bondwong/Documents/workspace/pamela/target/data/pamela.db".
Here is the Spring configuration:
<bean id="graphDbBuilder" factory-bean="graphDbFactory"
factory-method="newEmbeddedDatabaseBuilder">
<constructor-arg value="target/data/pamela.db" />
</bean>
Then I changed this line of neo4j-server.properties:
org.neo4j.server.database.location=/Users/bondwong/Documents/workspace/pamela/target/data/pamela.db
After that, I used curl to test my system, which showed all is good. Here is the result of getting a node whose id is 9:
However, when I fired up the server, and use the browser to see the data, nothing shows up:
Here is the location, it is the same as the one in the Spring XML configuration file:
Here is the :sysinfo result:
Here is the jUnit test and its result, showing that it actually insert the data:
package repositoryTest;
import static org.junit.Assert.*;
import java.util.HashMap;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import com.bond.pamela.domain.Diary;
import com.bond.pamela.domain.factory.DiaryFactory;
import com.bond.pamela.persistence.DirayRepository;
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration({ "/applicationContext.xml" })
public class DiaryRepositoryTest {
#Autowired
DirayRepository repository;
#Test
#Transactional
public void testSaveDiary() {
Diary diary = (Diary) DiaryFactory.getInstance().create(
new HashMap<String, Object>());
repository.save(diary);
Diary retrivedDiary = repository.findOne(diary.getGraphId());
assertEquals(diary, retrivedDiary);
}
}
I think it should work, someone knows what is wrong? and how to fix it. Thx!
You can write your java code as server extension
or use WrappingBootstrapper for the time being.
Or rather use ServerControls from Neo4j-Harness for testing
When creating the data, are you sure you committed the transaction correctly?
Transaction tx = db.beginTx();
// create data
tx.success();
tx.close();
or better
try (Transaction tx = db.beginTx()) {
// create data
tx.success();
}
I'm using spring-security 3.2.4.RELEASE , spring-security-aspects 3.2.4.RELEASE, AspectJ maven plugin version 1.6, Java 7.
I using AspectJ's weaving and not SpringAOP, therefore my aspectj maven plugin looks like this:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<Xlint>ignore</Xlint>
<showWeaveInfo>true</showWeaveInfo>
<source>${java.version}</source>
<target>${java.version}</target>
<complianceLevel>${org.aspectj-version}</complianceLevel>
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
</plugin>
I have another aspect that looks like this:
package com.mycompany.fw.app.config;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.DeclarePrecedence;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.ParameterNameDiscoverer;
import org.springframework.security.core.parameters.DefaultSecurityParameterNameDiscoverer;
import com.mycompany.fw.security.Integration;
#Aspect
#DeclarePrecedence("IntegrationAspects*,*")
public class IntegrationAspects {
ParameterNameDiscoverer parameterNameDiscoverer = new DefaultSecurityParameterNameDiscoverer();
#Pointcut("(execution(* com.mycompany..*(..))) && #annotation(integrate) ")
public void integratePointCut(Integration integrate) {
}
/**
* TODO: cache
*
* #param jp
* #param integrate
* #throws Throwable
*/
#Around("integratePointCut(integrate)")
public Object integrate(final ProceedingJoinPoint pjp, Integration integrate) throws Throwable {
Object res = pjp.proceed();
return res;
}
}
What I need is to put the above (integration aspect) to be the first before any other aspect (including Spring's security aspect)
As you can see I tried it with #DeclarePrecedence (I also tried it with declare precedence : IntegrationAspects*,* as well in an .aj file), unfortunately, without success.
Can someone instruct me how to define the aspects invocation order?
The problem is that you do not use the plain aspect name IntegrationAspects in #DeclarePrecedence, but a joker character *. In this case you need to use a fully qualified class name or jokers creating same.
Does not work:
#DeclarePrecedence("IntegrationAspects*, *")
Works:
#DeclarePrecedence("IntegrationAspects, *")
#DeclarePrecedence("com.mycompany.fw.security.Integration.IntegrationAspects, *")
#DeclarePrecedence("com.mycompany.fw.security.Integration.IntegrationAspects*, *")
#DeclarePrecedence("*..IntegrationAspects*, *")
And so forth. By the way, using upper-case package names and plurals in class names looks really ugly.
I am an AspectJ expert, not a Spring user, so I cannot tell you if declaring precedence will also affect Spring-provided aspects. It might also depend on whether they are implemented using native AspectJ or Spring-AOP (proxy-based "AOP lite").
I have a podo class CarStorage for angular to inject.
class CarStorage {
int _carIdCounter = 0;
...
I wire it in using type:
module
..type(CarForm)
..type(CarItemsList)
..type(CarStorage)
;
It works in dartium but fails to load in dart2js. I get the following error:
Illegal argument(s): No type factory provided for CarStorage! (resolving GarageAppController -> CarStorage)
I discovered through some bug reports and guess work you need to add the DI Injectable annotation:
import "package:angular/angular.dart";
#Injectable()
class CarStorage {
...
edit: Fixed the import.
Do NOT use import 'package:di/annotations.dart'; this causes errors
In my Grails app, I need to bind a request parameter to a Date field of a command object. In order to perform the String-to-Date conversion, one needs to register an appropriate PropertyEditor in grails-app\conf\spring\resources.groovy
I've added the following bean definiton:
import org.springframework.beans.propertyeditors.CustomDateEditor
import java.text.SimpleDateFormat
beans = {
paramDateEditor(CustomDateEditor, new SimpleDateFormat("dd/MM/yy"), true) {}
}
But I'm still getting an error:
java.lang.IllegalArgumentException: Could not parse date: Unparseable date: "04/01/99"]
I think there's probably just something wrong with the way I've defined the bean, but I've no idea what?
The piece you are missing is registering of the new property editor. The following worked for me when I upgraded to Grails 1.1 and had to bind dates in the MM/dd/yyyy format.
grails-app/config/spring/resources.groovy:
beans = {
customPropertyEditorRegistrar(util.CustomPropertyEditorRegistrar)
}
src/groovy/util/CustomPropertyEditorRegistrar.groovy:
package util
import java.util.Date
import java.text.SimpleDateFormat
import org.springframework.beans.propertyeditors.CustomDateEditor
import org.springframework.beans.PropertyEditorRegistrar
import org.springframework.beans.PropertyEditorRegistry
public class CustomPropertyEditorRegistrar implements PropertyEditorRegistrar {
public void registerCustomEditors(PropertyEditorRegistry registry) {
registry.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("dd/MM/yy"), true));
}
}