Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java.time.Instant cannot be cast to java.util.Date even persisted as Date #267

Open
kyeljmd opened this issue Nov 18, 2018 · 1 comment
Open

Comments

@kyeljmd
Copy link

kyeljmd commented Nov 18, 2018

Here's a snippet of my code

@label("trip")
case class TripModel(tripId: Option[String] = None,
                     name: String,
                     createdDate: Date = new Date(),
                     startDate: Date,
                     duration: Int,
                     totalAdults: Int,
                     totalChildrens: Int,
                     @underlying vertex: Option[Vertex] = None
                    )

I am able to persist a trip model using the following code..



    val trip  = TripModel(tripId = Some(randomUUID.toString), name = ctr.tripName,
      startDate = DateUtil.convertStringToDate(ctr.startTo), duration = ctr.totalDays,
      totalAdults = ctr.totalAdults, totalChildrens = ctr.totalChildren, createdDate = new Date())

    val tripVertex = graph + trip

However upon retrieval of the persisted vertex I always receive this error.


play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[ClassCastException: java.time.Instant cannot be cast to java.util.Date]]
	at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:251)
	at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:178)
	at play.core.server.AkkaHttpServer$$anonfun$1.applyOrElse(AkkaHttpServer.scala:363)
	at play.core.server.AkkaHttpServer$$anonfun$1.applyOrElse(AkkaHttpServer.scala:361)
	at scala.concurrent.Future.$anonfun$recoverWith$1(Future.scala:413)
	at scala.concurrent.impl.Promise.$anonfun$transformWith$1(Promise.scala:37)
	at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:60)
	at akka.dispatch.BatchingExecutor$AbstractBatch.processBatch(BatchingExecutor.scala:55)
	at akka.dispatch.BatchingExecutor$BlockableBatch.$anonfun$run$1(BatchingExecutor.scala:91)
	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
Caused by: java.lang.ClassCastException: java.time.Instant cannot be cast to java.util.Date
	at service.TripService$$anon$1.toCC(TripService.scala:30)
	at service.TripService$$anon$1.toCC(TripService.scala:30)
	at gremlin.scala.ScalaVertex.toCC(ScalaVertex.scala:12)
	at service.TripService.getTrip(TripService.scala:30)
	at controllers.trip.TripController.$anonfun$getTrip$1(TripController.scala:28)
	at play.api.mvc.ActionBuilder.$anonfun$apply$11(Action.scala:363)
	at scala.Function1.$anonfun$andThen$1(Function1.scala:52)
	at play.api.mvc.ActionBuilderImpl.invokeBlock(Action.scala:482)
	at play.api.mvc.ActionBuilderImpl.invokeBlock(Action.scala:480)
	at play.api.mvc.ActionBuilder$$anon$9.invokeBlock(Action.scala:331)
@mpollmeier
Copy link
Owner

Hard to tell without a simple executable example, but looks like some class in the middle instantiates an Instant and not a Date. Here's a simple example that works:

import gremlin.scala._
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph

case class CCWithDate(d: java.util.Date)

val graph = TinkerGraph.open.asScala
val cc = CCWithDate(new java.util.Date)
val v = graph + cc
println(v.toCC[CCWithDate])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants