小编ElG*_*abe的帖子

使用Scala / Play将JSON转换为带有嵌套对象的case类

说我正在使用的JSON响应的格式如下:

[
    {
       "make": "Tesla",
       "model": "Model S",
       "year": 2017,
       "color": "red",
       "owner": "Bob",
       "max_speed": 200,
       "wheel_size": 30,
       "is_convertible": true,
       "license": "ABC123",
       "cost": 50000,
       "down_payment": 2500,
       "other_property_1": 1,
       "other_property_2": 2,
       "other_property_3": 3,
       "other_property_4": 4,
       "other_property_5": 5,
       "other_property_6": 6,
       "other_property_7": 7,
       "other_property_8": 8,
       "other_property_9": 9,
       "other_property_10": 10,
       "other_property_11": 11
    }
]
Run Code Online (Sandbox Code Playgroud)

此处的JSON是汽车对象的数组(为简单起见,仅为1),我正在尝试使用JSON Reads转换器将其转换为模型。假设我有一个Car案例类来表示每个对象,并且该类具有嵌套的FinancialInfo案例类,以在逻辑上拆分属性的数量,从而避免了Scala的22参数限制。

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

case class Car(
    make: String,
    model: String,
    year: Int,
    color: String,
    owner: String,
    maxSpeed: Int,
    wheelSize: Int,
    isConvertible: Boolean,
    license: String,
    financialInfo: FinancialInfo, // …
Run Code Online (Sandbox Code Playgroud)

parsing json scala playframework

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

如何在PostgreSQL中执行完全匹配,后跟ORDER BY

我正在尝试编写一个查询,该查询将一些结果(在我的情况下为单个结果)放在顶部,然后对其余结果进行排序。我尚未找到PostgreSQL解决方案。

说我有一个airports像这样的桌子。

 id | code |        display_name         
----+------+----------------------------
  1 | SDF  | International               
  2 | INT  | International Airport       
  3 | TES  | Test                        
  4 | APP  | Airport Place International
Run Code Online (Sandbox Code Playgroud)

简而言之,我在控制器方法中有一个查询,当用户文本通过code或搜索机场时,该查询将被异步调用display_name。但是,当用户输入的输入code完全匹配时(机场代码是唯一的),我希望该结果首先出现,然后所有int在其中也要display_name升序显示的机场。如果不存在完全匹配项,则应返回所有按display_name升序排序的通配符匹配项。因此,如果用户输入INT(2, INT, International Airport)则应首先返回该行,然后再返回其他行:

Results:
1. INT | International Airport
2. APP | Airport Place International
3. SDF | International
Run Code Online (Sandbox Code Playgroud)

这是我正在修改的查询的一种,它在我的应用程序上下文之外进行了稍微简化以使其有意义,但是仍然具有相同的概念。

SELECT * FROM airports
WHERE display_name LIKE 'somesearchtext%'
ORDER BY …
Run Code Online (Sandbox Code Playgroud)

sql postgresql sql-order-by case-when columnsorting

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