小编ars*_*265的帖子

杰克逊杰森类型映射内部类

我正在尝试为作为JSON传入的对象创建内部类类型,但是虽然我已经阅读了这里以及Jackson的网站,但我似乎无法获得正确的组合,所以如果其他人有任何指针他们将非常感激.我在下面发布了一些片段并删除了所有的getter和setter,我没想到他们需要发帖.我正在使用Jackson 2.2.

我试图反序列化的类:

public class Settings {
  private int offset;
  private int limit;
  private String type;
  private Map<String, Criteria> criteria;

  public class Criteria {
    private String restriction;
    private Object value;
  }
}
Run Code Online (Sandbox Code Playgroud)

我用来反序列化的代码:

ObjectMapper om = new ObjectMapper();
TypeFactory tf = om.getTypeFactory();
JavaType map = tf.constructMapLikeType( Map.class, String.class, Criteria.class );
JavaType type = typeFactory.constructType( Settings.class, map );
Settings settings = om.readValue( entity, type );
Run Code Online (Sandbox Code Playgroud)

我的JSON测试数据:

{ "type": "org.json.Car", "criteria": { "restriction": "eq", "value": "bmw" } }
Run Code Online (Sandbox Code Playgroud)

java mapping jackson

22
推荐指数
2
解决办法
4万
查看次数

Java添加到未知类型的通用列表

我之前遇到过一些我在Java中没有遇到过的东西,也就是说,我需要在运行时创建一个新的ArrayList类实例而不分配已知类型然后将数据添加到列表中.这听起来有点模糊,所以这是一个例子:

Class<?> c = i.getClass();

Constructor<?> con = ArrayList.class.getConstructor();
ArrayList<?> al = (ArrayList<?>)con.newInstance();

al.add("something");
Run Code Online (Sandbox Code Playgroud)

现在我这样做而不仅仅使用泛型的原因是因为泛型已经被大量使用而且这个例子中的"i"变量将被用作类型"?".我真的不想投入另一个通用,因为这会给用户带来更多的工作,并且在最终设计中会更不灵活.有没有办法使用下面的东西(注意:下面的内容不起作用).有人有想法吗?

ArrayList<c> al = (ArrayList<c>)con.newInstance();
Run Code Online (Sandbox Code Playgroud)

java generics reflection classloader

13
推荐指数
3
解决办法
3万
查看次数

使用Canvas和JavaScript进行多边形表示的图像采样算法?

首先,我不习惯处理图像,所以如果我的措辞不对,请原谅.

我希望拍摄放在HTML5画布上的图像,对其进行采样,减少采样,然后使用主要使用其他几个多边形的三角形创建图像的多边形表示,并将该图像绘制到画布上.

但我不知道从哪个算法开始这样做.这种算法需要什么样的伪代码?

此图像可以更好地理解最终结果:

http://oi49.tinypic.com/1hcj2d.jpg

html javascript algorithm canvas image

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

错误C2143:语法错误:缺少';' 在'*'之前

我不是C++的新手,但我习惯于运行g ++编译器和微软的VS C++.我明白这个错误应该是什么意思.这应该意味着我错过了';' 在Polygon类之前或之类的行上.我似乎找不到任何错误.g ++编译代码时没有错误.似乎没有加载Polygon类.任何人都可以告诉我我想要的东西.我有下面的Application.cpp,Polygon.h和Polygon.cpp.

Application.cpp抛出错误,但如果我可以修复第一个其他错误将遵循:

application.cpp(121) : error C2143: syntax error : missing ';' before '*'
application.cpp(121) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
application.cpp(121) : error C2365: 'Polygon' : redefinition; previous definition was 'function' c:\program files\microsoft sdks\windows\v6.0a\include\wingdi.h(4203) : see declaration of 'Polygon'

#include <sstream>
#include <numeric>
#include <math.h>
#include "Polygon.h"

#define PI 3.14159265

//use standard namespace
using namespace std;

 /**************************** Window Variables ****************************/

double _window_height   = 500;
double _window_width   = …
Run Code Online (Sandbox Code Playgroud)

c++ visual-studio-2008

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

使用可更新JProgressBar的Java Swing线程

首先,我最近一直在使用Java的Concurrency软件包,但我发现了一个问题,我被困在了.我想拥有和应用程序和应用程序可以有SplashScreen一个状态栏和其他数据的加载.所以我决定使用SwingUtilities.invokeAndWait( call the splash component here ).在SplashScreen随后与出现JProgressBar并运行一组线程.但我似乎无法很好地处理事情.我已经查看SwingWorker并尝试将其用于此目的,但线程只是返回.这是一些伪代码.以及我正在努力实现的目标.

  • SplashScreen在加载信息时有一个暂停的应用程序
  • 能够在下运行多个线程 SplashScreen
  • SplashScreenUpdate-able 的进度条在所有线程完成之前都不会退出.

启动启动画面

try {
    SwingUtilities.invokeAndWait( SplashScreen );
} catch (InterruptedException e) {
} catch (InvocationTargetException e) { }
Run Code Online (Sandbox Code Playgroud)

飞溅屏幕结构

SplashScreen extends JFrame implements Runnable{

    public void run() {
        //run threads
        //while updating status bar
    }
}
Run Code Online (Sandbox Code Playgroud)

我尝试了很多东西,包括SwingWorkers使用CountDownLatch的Threads等等.CountDownLatch实际上以我想要处理的方式工作但我无法更新GUI.当使用SwingWorkers任一invokeAndWait已基本作废(这是他们的目的),或者使用时,它不会甚至仍在更新GUI PropertyChangedListener.如果其他人有一些想法,那么听听他们会很棒.提前致谢.

我实际上准备好发布更好的代码来帮助我找到我的解决方案.感谢所有帮助过的人.

java concurrency swing multithreading swingworker

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

Restlet响应类型

如何以所需格式返回Restlet响应?我使用的方法:

@Get ("json")
public Address sendResponse(){
    Address add = getAddress();
    return add;
}
Run Code Online (Sandbox Code Playgroud)

现在我必须显式地将java对象转换为json字符串作为对浏览器的响应.Restlet框架本身不能照顾它吗?

Spring MVC的Restful实现可以做到.我也在Restlet中寻找类似的实现.

java rest web-services spring-mvc restlet

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