小编man*_*ane的帖子

Scala案例有22个字段,但在scala 2.11.5中有play-json问题

使用Scala 2.11,我们可以在一个案例类中拥有超过22个字段吗?

case class SomeResponse(
                                     var compositeKey: String,
                                     var id1: String,
                                     var id2: String,
                                     var firstName: String,
                                     var lastName: String,
                                     var email: String,
                                     var email2: String,
                                     var birth: Long,
                                     var gender: String,
                                     var phone: Phone,
                                     var city: String,
                                     var zip: String,
                                     var carriage: Boolean,
                                     var carriage2: Boolean,
                                     var fooLong: Long,
                                     var fooLong2: Long,
                                     var suspended: Boolean,
                                     var foo: Foo,
                                     var address: String,
                                     var suite: String,
                                     var state: String,
                                     var instructions: String)

implicit val formatSomeResponse = Json.format[SomeResponse]
Run Code Online (Sandbox Code Playgroud)

以上是一个案例类,其中有正好22个字段与play-json格式,现在当我编译时,我得到这个错误:

SomeFile.scala:126: value apply …
Run Code Online (Sandbox Code Playgroud)

scala playframework playframework-2.3

27
推荐指数
2
解决办法
4158
查看次数

在 Scala 中将 JSON 转换为 CSV?

是否有任何可用的库可以将 JSON 字符串(很可能超过 1 行数据)转换为 CSV 文件。

我在 Scala 中搜索了很多这样的库,但我找不到。

我需要做的是从数据库源检索数据,结果集为 JSON 格式,并将它们转换为 CSV。

在我做的是将 JSON 转换为相关的 Seq[case-class] 之前,并尝试使用以下库:

但是在包含深层层次结构的案例类的情况下,这些并没有证明有多大用处。

有什么建议??

csv json scala

6
推荐指数
1
解决办法
5250
查看次数

如何在光滑的情况下为复杂的案例类创建投影类?

例如,我有这个案例类:

case class User(
  var identityId: IdentityId, //Its a user created class
  var firstName: String,
  var lastName: String,
  var fullName: String,
  var email: Option[String],
  var avatarUrl: Option[String],
  var authMethod: AuthenticationMethod,
  var oAuth1Info: Option[OAuth1Info] = None,
  var oAuth2Info: Option[OAuth2Info] = None,
  var passwordInfo: Option[PasswordInfo] = None) extends Identity {

  def this() = this(null, "", "", "", None, None, null, None, None, None)

}
Run Code Online (Sandbox Code Playgroud)

它实际上是一个secSecocial标识,现在identityId是一个case类的对象:

case class IdentityId(
var userId:String,
var providerId:String
)
Run Code Online (Sandbox Code Playgroud)

那么如何为像这样的情况创建一个投影类?如果我必须创建一个类似String的投影类数据类型,那么它本来就没有问题但是用户定义的对象和类呢?

scala slick play-slick slick-2.0

6
推荐指数
1
解决办法
3305
查看次数

亚马逊S3图片,无法使用html5画布保存,给出了污染画布错误

使用canvas来保存图像(Chrome,Firefox和Safari)时遇到问题,

当我在html5画布中加载托管图像时,画布中会显示错误(尽管仅在Chome而不是Firefox中),该图像来自Amazon S3服务器:

Image from origin 'https://xxx.s3.amazonaws.com' has been blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9015' is therefore not allowed access.

当我尝试将画布保存为图像时,

Uncaught SecurityError: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported.

是的,我已经设置了CORS配置,

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedMethod>GET</AllowedMethod>
        <AllowedHeader>*</AllowedHeader>
    </CORSRule>
</CORSConfiguration>
Run Code Online (Sandbox Code Playgroud)

img.crossOrigin = 'something'
Run Code Online (Sandbox Code Playgroud)

我查看了Respond Proxy Js,但无法理解如何使用它.

我查看了很多SO帖子和其他参考文献,但无法解决问题.任何人都可以为我提供任何解决方案.

@Update:如果我更改了line <AllowedOrigin>*</AllowedOrigin>=> <AllowedOrigin>http://localhost:9015</AllowedOrigin>,解决方案似乎允许Chrome保存画布Image,但问题仍然存在于Firefox和Safari中

html5 canvas amazon-s3 amazon-web-services cors

5
推荐指数
1
解决办法
2024
查看次数

为Scup的Seq播放Scala Json作家

我正在尝试找到一种方法来使用内置的Macro Json Writer来序列化Seq [(String,Customer)]

我设法为Seq [Customer]做了这个,但是当添加touple时,编译器开始尖叫我.

此代码有效:

package models.health

import play.api.libs.json._

case class Customer(name: String, age: Int)

//we use the dummy var as a workaround to the json writer    limitations (cannot handle single argument case class)
case class Demo(customers: Seq[Customer], dummy: Option[String] =    None)

object Demo {

 import play.api.libs.functional.syntax._

 implicit val customer_writer = Json.writes[Customer]

 implicit val writes: Writes[Demo] = (
 (__ \ "customers").write[Seq[Customer]] and
 (__ \ "dummy").writeNullable[String]) { 
    (d: Demo) => (d.customers,d.dummy)
 }

}
Run Code Online (Sandbox Code Playgroud)

但是下面的代码(只需从Seq [Customer]更改为Seq [(String,Customer)]不会Copmile ...真的很感激任何帮助:

package models.health …
Run Code Online (Sandbox Code Playgroud)

json scala playframework

4
推荐指数
1
解决办法
3332
查看次数

跟踪信用卡,任何API的交易数据?

我需要创建一个收集银行账户交易详情的应用程序,有像这样的API

但是这些API使用客户端用户名密码来检索交易数据,但在我的情况下,我只需要使用信用卡号码.

甚至可以做到吗?

是否有其他API提供此功能?

我已经对这个问题进行了很多研究,但似乎仍然无法找到任何符合要求的API.感谢任何帮助,谢谢.

onlinebanking credit-card-track-data yodlee plaid

3
推荐指数
1
解决办法
2461
查看次数

Play 2.2.2 (Scala),如何处理HttpServletRequests

我对 Play 和 Scala 还很陌生,遇到了一个问题,就像:简单的解释,

www.somesite.com/redirectedFoo //points to below controller

def redirectedFoo = Action{
//The http request needs to be traced here,
//and it needs to be accessed by a Java API method

val obj=new SampleMethod(--need http request obj as argument--)

//my problem is Play request and Http request are totally different 'objects', 
//and the above method uses HttpServletRequest obj, how is this handled in Play
}
Run Code Online (Sandbox Code Playgroud)

对不起,我无法提供正确的解释,

java servlets scala playframework-2.0

2
推荐指数
1
解决办法
787
查看次数

当案例类和对象名称相同时,Scala 与 slick 2 出现问题

好吧,实际上我对类名有一些问题,这是我的问题

我有一个这样的案例类,

case class Foo(
  val compositeKey: String, // clientId-now-requestId
  val requestPath: String,
  val requestStatus: String) {

  def this() = this("", "", "")
  def someData = this.compositeKey.split("-")(0)
  def someData2 = this.compositeKey.split("-")(2)
}
Run Code Online (Sandbox Code Playgroud)

以及 Slick 的投影类,

class Foos(tag: Tag) extends Table[Foo](tag, "Foo") {

  def compositeKey: Column[String] = column[String]("composite_key", O.PrimaryKey)
  def requestPath: Column[String] = column[String]("request_path")
  def requestStatus: Column[String] = column[String]("request_status")
  def * : ProvenShape[ClientApiLog] = (compositeKey, requestPath, requestStatus) <> (Foo.tupled, Foo.unapply) //Error is thrown in this line
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,案例类名==对象

object Foo { …
Run Code Online (Sandbox Code Playgroud)

mysql scala slick-2.0

1
推荐指数
1
解决办法
742
查看次数

在运行时从scala中的case类对象中检索fieldname和value

示例案例类:尝试创建通用查询构建器

case class BaseQuery(operand: String, value: String)
case class ContactQuery(phone: BaseQuery, address: BaseQuery)
case class UserQuery(id: BaseQuery, name: BaseQuery, contact: ContactQuery)

val user = UserQuery(BaseQuery("equal","1"), BaseQuery("like","Foo"), ContactQuery(BaseQuery("eq","007-0000"),BaseQuery("like", "Foo City")))


//case class Contact(phone: String, address: String)

//case class User(id: Long, name: String, contact: Contact)

//val user = User(1, "Foo Dev", Contact("007-0000","Foo City"))
Run Code Online (Sandbox Code Playgroud)

我们如何在scala中检索字段名称和相应的值,

在进一步研究中,

使用Scala反射的解决方案:

def classAccessors[T: TypeTag]: List[MethodSymbol] = typeOf[T].members.collect {
    case m: MethodSymbol if m.isCaseAccessor => m
}.toList

// The above snippet returns the field names, and as input …
Run Code Online (Sandbox Code Playgroud)

scala scala-reflect

1
推荐指数
1
解决办法
1182
查看次数