我刚刚开始使用RestKit 0.20.0,我在创建格式良好的JSON请求时遇到了麻烦.
我得到这个(从休息套件日志):
request.body=title=A%20glorious%20walk%20in%20the%20woods&startDateTime=2013-01-13%2016%3A09%3A33%20%2B0000&endDateTime=2013-01-13%2016%3A09%3A43%20%2B0000&points[][longitude]=-122.0307725&points[][latitude]=37.3310798&points[][longitude]=-122.0307334&points[][latitude]=37.33154242&points[][longitude]=-122.03075743&points[][latitude]=37.33138305&points[][longitude]=-122.03075659&points[][latitude]=37.33131185&points[][longitude]=-122.03057969&points[][latitude]=37.33156519&points[][longitude]=-122.03075535&points[][latitude]=37.33144466&points[][longitude]=-122.03076342&points[][latitude]=37.33123666&points[][longitude]=-122.03074488&points[][latitude]=37.33149482&points[][longitude]=-122.03068145&points[][latitude]=37.33155419&points[][longitude]=-122.03062909&points[][latitude]=37.33156564&points[][longitude]=-122.03076853&points[][latitude]=37.33115792
Run Code Online (Sandbox Code Playgroud)
当我想要这个(带有大括号的普通json对象和points属性的数组)时:
{
title: "Something",
startDateTime: "dateinfo",
endDateTime: "moredateinfo",
points: [
{
latitude: "37.33131313",
longitude: "122.4325454"
},
{
latitude: "37.33131313",
longitude: "122.4325454"
}
]
}
Run Code Online (Sandbox Code Playgroud)
我有两个主要对象:一个DLWalk包含一个DLPoint对象的NSSet(它们是CoreData对象,但目前我忽略了它,只关注创建一个HTTP请求)
这是我用来创建请求的代码:
// Point mapping
RKObjectMapping *mappingPoint = [RKObjectMapping requestMapping];
[mappingPoint addAttributeMappingsFromArray:@[@"latitude", @"longitude"]];
RKRequestDescriptor *reqDescPoint = [RKRequestDescriptor requestDescriptorWithMapping:mappingPoint objectClass:[DLPoint class] rootKeyPath:nil];
// Walk mapping
RKObjectMapping *mappingWalk = [RKObjectMapping requestMapping];
[mappingWalk addAttributeMappingsFromArray:@[@"endDateTime", @"startDateTime", @"title"]];
RKRequestDescriptor *reqDescWalk = [RKRequestDescriptor requestDescriptorWithMapping:mappingWalk objectClass:[DLWalk class] rootKeyPath:nil];
// Define the relationship mapping
[mappingWalk addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"points" toKeyPath:@"points" withMapping:mappingPoint]];
RKObjectManager …Run Code Online (Sandbox Code Playgroud) 我希望能够在我的 jhipster 应用程序中看到 swagger rest api 文档,即使它在 prod 配置文件下运行也是如此。目前它只显示在开发配置文件中,我不确定它的配置位置。
我的 jhipster v2.23.1 应用程序使用自定义序列化器和反序列化器进行 JSON 解析,我在JacksonConfiguration. REST API 使用我的自定义映射按预期工作。
但是,自动生成的 swagger 文档中显示的 JSON 不反映自定义映射。我希望 swagger 会自动检测自定义序列化器/反序列化器,但由于它没有,我怎样才能让 swagger 显示我的自定义 JSON 格式而不是它自己检测到的格式?
基于http://springfox.github.io/springfox/docs/current/#configuring-springfox上的 springfox 文档,我实现了接口:
ApplicationListener<ObjectMapperConfigured>
Run Code Online (Sandbox Code Playgroud)
在我的 SwaggerConfiguration bean 中。我可以看到该onApplicationEvent(ObjectMapperConfigured event)方法被调用了两次。映射器第一次将按预期序列化我的对象,第二次则不会。如果我向映射器注册我的模块,它似乎也没有什么区别。我在这里工作的对象是一个联系人。
@Override
public void onApplicationEvent(ObjectMapperConfigured event) {
ObjectMapper mapper = event.getObjectMapper();
// Custom serialization for Contact objects
SimpleModule contactModule = new SimpleModule("Contact Module");
contactModule.addSerializer(new ContactSerializer(Contact.class));
contactModule.addDeserializer(Contact.class, new ContactDeserializer(Contact.class));
mapper.registerModule(contactModule);
// My custom object
Contact c = new Contact();
c.setCity("Springfield");
c.setEmail("someone@gmail.com");
String contactJsonStr = null;
try { …Run Code Online (Sandbox Code Playgroud) 当我调用context.drawImageChrome 81+ 时,它会自动旋转图像。我想禁用它。我可以在 img 标签中使用 禁用它image-orientation:none,但这在画布上不起作用。
它似乎忽略了图像方向样式。在下面的这个例子中,img 标签不会自动旋转(如预期的那样),但画布会自动旋转,尽管尝试禁用它。
你如何防止drawImage根据 exif 数据旋转,或者至少检测到它已经这样做了?
<html>
<head>
<script>
window.onload = function() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
var img = document.getElementById("imgtest");
// This style is ignored
img.style.imageOrientation = 'none';
ctx.drawImage(img, 0, 0);
};
</script>
</head>
<body>
<p>
<img id="imgtest" style="image-orientation:none;" src="portrait.jpg"/>
<canvas id="myCanvas" width="240" height="297"></canvas>
</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 我试图了解如何使用WCF数据服务(基于EF 4.1)来创建一个宁静的Web服务,该服务将持久化作为JSON对象传递的实体.
我已经能够创建一个方法,可以接受带有一组原始数据类型作为参数的GET请求.我不喜欢这个解决方案,我更喜欢在http请求体中发送带有JSON对象的POST请求.
我发现我无法让框架将json序列化为一个对象,但是我可以手动完成它.
我的问题是我似乎无法读取POST请求的正文 - 正文应该是JSON有效负载.
下面是一个粗略的裂缝.我已经尝试了几次不同的迭代,似乎无法从请求体中获取原始JSON.
有什么想法吗?更好的方法吗?我只想发布一些JSON数据并进行处理.
[WebInvoke(Method = "POST")]
public void SaveMyObj()
{
StreamReader r = new StreamReader(HttpContext.Current.Request.InputStream);
string jsonBody = r.ReadToEnd(); // jsonBody is empty!!
JavaScriptSerializer jss = new JavaScriptSerializer();
MyObj o = (MyObj)jss.Deserialize(jsonBody, typeof(MyObj));
// Now do validation, business logic, and persist my object
}
Run Code Online (Sandbox Code Playgroud)
我的DataService是一个扩展的实体框架DataService
System.Data.Services.DataService<T>
Run Code Online (Sandbox Code Playgroud)
如果我尝试将非原始值作为参数添加到方法中,我会在跟踪日志中看到以下异常:
System.InvalidOperationException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
'Void SaveMyObj(MyNamespace.MyObj)' has a parameter 'MyNamespace.MyObj o' of type 'MyNamespace.MyObj' which is not supported for service operations. Only primitive types are supported …Run Code Online (Sandbox Code Playgroud) 我有java Spring Security应用程序(用jhipster构建),我正在尝试添加一些基于当前经过身份验证的用户测试逻辑的单元测试.
为此,我已将我的MockMvc对象配置为使用Web应用程序上下文和弹簧安全性,如下所示:
@Test
@Transactional
public void getAllContacts() throws Exception {
restContactMockMvc = MockMvcBuilders
.webAppContextSetup(context)
.apply(springSecurity())
.build();
restContactMockMvc.perform(get("/api/contacts")).andExpect(status().isOk());
}
Run Code Online (Sandbox Code Playgroud)
问题是我还将应用程序配置为需要HTTPS,每当我运行此单元测试时,我都会收到302重定向响应,因为它似乎试图发送HTTP请求而不是HTTPS.
我强制执行HTTPS的方式是使用以下行SecurityConfiguration.configure(HttpSecurity http):
if (env.acceptsProfiles("!dev"))http.requiresChannel().anyRequest().requiresSecure();
Run Code Online (Sandbox Code Playgroud)
所以,我的问题是如何让我的单元测试正确运行?可能是通过发送模拟HTTPS请求,还是通过在运行单元测试时禁用HTTPS?
我有一个.NET代码,首先是我使用属性配置的EF 4.1对象集.
我想重命名用作我的Type-Per-Hierarchy继承的鉴别器的列,并且还控制鉴别器列的值.
我已经看到了如何使用流畅的映射执行此操作的示例,但由于我在其他地方使用属性,因此我希望保持一致并使用属性进行配置.这甚至可能吗?
java ×3
jhipster ×3
json ×3
c# ×2
swagger ×2
.net ×1
css ×1
html ×1
html5-canvas ×1
ios ×1
javascript ×1
restkit ×1
spring-mvc ×1
springfox ×1
unit-testing ×1